Author Topic: Drawing Tilemaps for Flixel using Mappy.  (Read 33331 times)

Scrufalicious

  • Guest
Re: Drawing Tilemaps for Flixel using Mappy.
« Reply #20 on: Wed, Dec 2, 2009 »
Still curious if anyone knows how to fix this. Haven't heard any responses and I'm stumped...  :-\

shortstalker

  • Member
  • **
  • Posts: 19
  • Karma: +0/-0
    • View Profile
Re: Drawing Tilemaps for Flixel using Mappy.
« Reply #21 on: Sun, Dec 13, 2009 »
I've rewritten the LUA code attached above to export multiple layers.

When you give your map a name, say text.txt it exports the layers as:

text_L0.txt
text_L1.txt
text_L2.txt
etc...


I can't seem to get it to upload, so here it is in code form.

Enjoy!

code:
Quote
-- Export Flash actionscript
-- Thanks to Andre Michelle for the idea
-- multiple layer mod. by Mike


function main ()
 if mappy.msgBox ("Export Flixel Tilemap", "This will export the current layer as a Flixel Tilemap (anims are replaced with block 0)\n\nRun the script (you will be prompted for a filename to save as)?", mappy.MMB_OKCANCEL, mappy.MMB_ICONQUESTION) == mappy.MMB_OK then

  local w = mappy.getValue(mappy.MAPWIDTH)
  local h = mappy.getValue(mappy.MAPHEIGHT)
  local layers = mappy.getValue(mappy.NUMLAYERS)

  if (w == 0) then
   mappy.msgBox ("Export Flash actionscript", "You need to load or create a map first", mappy.MMB_OK, mappy.MMB_ICONINFO)
  else

   local isok,asname = mappy.fileRequester (".", "Flixel Tilemap (*.txt)", "*.txt", mappy.MMB_SAVE)
   if isok == mappy.MMB_OK then

    if ((string.sub (string.lower (asname), -4) == ".txt")) then
     asname = string.sub (string.lower (asname), 1, string.len(asname)-4)
    end

    local isok,adjust = mappy.doDialogue ("Export Flixel Tilemap", "Adjust exported values by:", "-1", mappy.MMB_DIALOGUE1)
    if isok == mappy.MMB_OK then
   
     adjust = tonumber (adjust)
     local l = 0
     while l < layers do
       outas = io.open (asname .. "_L" .. tostring(l) .. ".txt", "w")
       local y = 0
       while y < h do
        local x = 0
        while x < w do
         local mapval = mappy.getBlockValue (mappy.getBlock (x, y, l), mappy.BLKBG)
         mapval = mapval + adjust
         if mapval < 0 then
          mapval = 0
         end
         outas:write (tostring(mapval))
         if x < (w-1) then
          outas:write (",")
         else
          if y < (h-1) then
      outas:write ("\n")
     else
      outas:write ("\n")
      end
         end
        x = x + 1
        end
        y = y + 1
       end
        outas:write ("\n")
   outas:close()
       l = l + 1
      end

    end
   end
  end
 end
end

test, errormsg = pcall( main )
if not test then
    mappy.msgBox("Error ...", errormsg, mappy.MMB_OK, mappy.MMB_ICONEXCLAMATION)
end


Titch

  • Contributor
  • ****
  • Posts: 270
  • Karma: +0/-0
  • Thing with the guy in the place.
    • View Profile
Re: Drawing Tilemaps for Flixel using Mappy.
« Reply #22 on: Sun, Dec 13, 2009 »
Ummm, the code already exports multiple layers. The whole point was the create a system where a bunch of layers are all embedded into one XML.

Not that having a pure text export is a bad things :P
Free cake whippings every day at #flixel on irc.freenode.net.

shortstalker

  • Member
  • **
  • Posts: 19
  • Karma: +0/-0
    • View Profile
Re: Drawing Tilemaps for Flixel using Mappy.
« Reply #23 on: Sun, Dec 13, 2009 »
My bad, the lua that I got was from the starter tutorial that makes the Ninja game. I didn't bother looking at the LUA you had created because I thought they were the same.

cheers!

murkinesis

  • Member
  • **
  • Posts: 57
  • Karma: +0/-0
    • View Profile
Re: Drawing Tilemaps for Flixel using Mappy.
« Reply #24 on: Thu, Dec 17, 2009 »
Titch,
do I understand that your new script can export multiple layers in one map? If so, how do I import an XML map rather than a TXT one?

PlayOrDie

  • Active Member
  • ***
  • Posts: 151
  • Karma: +0/-0
  • Game Over
    • View Profile
Re: Drawing Tilemaps for Flixel using Mappy.
« Reply #25 on: Sat, Dec 19, 2009 »
Not that having a pure text export is a bad things :P

@Titch

Your solution using marker tiles (by editing mappy's block properties) for Flixel sprites seems clean enough, I am going to try it out your example code and script tonight.

@shortstalker

Having the layers as separate text files seem reasonable enough - if slightly less efficient than a single XML (I know you didn't notice that), but my main concern with your method of multiple txt files is how to parse the sprite layers csv (txt file) into an array of integers for sprite placement.

[EDIT]

Titch,
do I understand that your new script can export multiple layers in one map? If so, how do I import an XML map rather than a TXT one?

I tried this out tonight and also had problems embedding and parsing the xml file that is exported from Mappy.  All 3 layers in the supplied example seem to export correctly when I looked at the resulting xml file in notepad, however I am also not sure how to deal with this in Flixel, despite Titch's guidelines earlier in this thread.

@ Titch: forgive my directness, but would you mind helping us poor xml noobs a bit more with importing into flixel and setting up the layers? :)  Even the xml embedding tutorials I found on the www didn't seem to make it work for me after trying for an hour or two.  Also, thanks for the great help so far with mappy.
« Last Edit: Sat, Dec 19, 2009 by Badger Manf. »
Make it work reliably and fast.
Donald Lebeau - Gauntlet

Titch

  • Contributor
  • ****
  • Posts: 270
  • Karma: +0/-0
  • Thing with the guy in the place.
    • View Profile
Re: Drawing Tilemaps for Flixel using Mappy.
« Reply #26 on: Sun, Dec 20, 2009 »
I'll see what I can do. I mentioned somewhere a while back that the script now has two 'branches'. A generic version and a *Up development version. I probably won't have time to write anything up untill after christmas now. :|
Free cake whippings every day at #flixel on irc.freenode.net.

jeanpier

  • Guest
Re: Drawing Tilemaps for Flixel using Mappy.
« Reply #27 on: Mon, Dec 21, 2009 »
I have been playing with mappy and lua today. And I modified the script a little to:
Layer0-> Export tiles (level_tiles.txt)
Layer1-> Export sprites (level_sprites.txt)

The sprites are adjusted to -91, so I have a lot of space for my tiles if I need a couple more. This way I can work with a single bitmap.

Notes: My tilemap has the first tile black (no need to adjust -1, removed). Sprites are 40x40. Sprites are positioned starting 90 tiles below (adjust -90), so my sprites array start at 01 in my level_sprites.txt.
The combined tiles/sprites bitmap is only used in Mappy just for reference.

Just look the script and adjust the second layer to your needs (adjust = startSprites - 1).

Something simple and very not optimized but works for my maps so far.

Code: [Select]
-- Export Flash actionscript
-- Thanks to Andre Michelle for the idea
-- multiple layer mod. by Mike


function main ()
 if mappy.msgBox ("Exportar Flixel Map", "Esto exportara dos Layers. El primero con los Tiles y el segundo con los

Sprites.(Deberás proporcionar un nombre para guardar el mapa)", mappy.MMB_OKCANCEL, mappy.MMB_ICONQUESTION) == mappy.MMB_OK

then

  local w = mappy.getValue(mappy.MAPWIDTH)
  local h = mappy.getValue(mappy.MAPHEIGHT)
  local layers = mappy.getValue(mappy.NUMLAYERS)

  if (w == 0) then
   mappy.msgBox ("Exportar Fixel Map", "Necesitas cargar o crear un mapa primero", mappy.MMB_OK, mappy.MMB_ICONINFO)
  else

   local isok,asname = mappy.fileRequester (".", "Flixel Tilemap (*.txt)", "*.txt", mappy.MMB_SAVE)
   if isok == mappy.MMB_OK then

    if ((string.sub (string.lower (asname), -4) == ".txt")) then
     asname = string.sub (string.lower (asname), 1, string.len(asname)-4)
    end
      -- Layer 0 TILES

  adjust = tonumber (0)

     local l = 0
       outas = io.open (asname .. "_tiles" .. ".txt", "w")
       local y = 0
       while y < h do
        local x = 0
        while x < w do
         local mapval = mappy.getBlockValue (mappy.getBlock (x, y, l), mappy.BLKBG)
         mapval = mapval + adjust
         if mapval < 0 then
          mapval = 0
         end
         outas:write (tostring(mapval))
         if x < (w-1) then
          outas:write (",")
         else
          if y < (h-1) then
      outas:write ("\n")
     else
      outas:write ("\n")
      end
         end
        x = x + 1
        end
        y = y + 1
       end
        outas:write ("\n")
   outas:close()
       l = l + 1

-- Layer 1 SPRITES

   adjust = tonumber (-90)
   outas = io.open (asname .. "_sprites" .. ".txt", "w")
       local y = 0
       while y < h do
        local x = 0
        while x < w do
         local mapval = mappy.getBlockValue (mappy.getBlock (x, y, l), mappy.BLKBG)
         mapval = mapval + adjust
         if mapval < 0 then
          mapval = 0
         end
         outas:write (tostring(mapval))
         if x < (w-1) then
          outas:write (",")
         else
          if y < (h-1) then
      outas:write ("\n")
     else
      outas:write ("\n")
      end
         end
        x = x + 1
        end
        y = y + 1
       end
        outas:write ("\n")
   outas:close()
   end
  end
 end
end

test, errormsg = pcall( main )
if not test then
    mappy.msgBox("Error ...", errormsg, mappy.MMB_OK, mappy.MMB_ICONEXCLAMATION)
end
 

Barts

  • Member
  • **
  • Posts: 61
  • Karma: +0/-0
    • View Profile
Re: Drawing Tilemaps for Flixel using Mappy.
« Reply #28 on: Sun, Feb 21, 2010 »
I just wanted to express my thanks to Titch and Shortstalker.

I have tried meddling with Flan and WasabiM and neither really pleased me, both crashed and I had problems integrating output with my file. Maybe I am just dumb. Still, I considered writing a C++ program to convert XML output of TileEd to something Flixel-readable, but then gave Mappy plus scripts a chance - and it turned out to be reasonably comfortable and rather easy to use.

Thanks a bunch, guys!

jonathanbruder

  • Guest
Re: Drawing Tilemaps for Flixel using Mappy.
« Reply #29 on: Sat, Apr 3, 2010 »
First of all, thanks much for posting this.

I'm working through part two of Seifer Tim's tutorial, and have used the method here to create my map with mappy.
Code: [Select]
 package com.Tutorial
{
    import org.flixel.*;

    public class PlayState extends FlxState
    {
[Embed(source = '../../org/flixel/data/tutorial-tiles.png')] private var ImgTiles:Class;
         [Embed(source = '../../org/flixel/data/map.txt', mimeType = "application/octet-stream")] private var GameMap:Class;
        
...

When I try to publish, I get the following error, followed by a repeated error that seems to be happening on update:

Quote
[Fault] exception, information=VerifyError: Error #1014: Class mx.core::ByteArrayAsset could not be found.
[Fault] exception, information=ReferenceError: Error #1065: Variable PlayState_GameMap is not defined.
flixel v2.32 [debug]
----------------------------------------------------
[Fault] exception, information=ReferenceError: Error #1065: Variable com.Tutorial::PlayState_GameMap is not defined.
Fault, PlayState() at PlayState.as:7
[Fault] exception, information=ReferenceError: Error #1065: Variable com.Tutorial::PlayState_GameMap is not defined.
Fault, PlayState() at PlayState.as:7

I'm (fairly) certain that flex.swc is in the correct place and that my AS3 context is correct. The reason I'm posting this in this thread is that the error disapparates when I comment out the map code. As expected, my player appears on screen and falls to his doom; no error.

I understand that ByteArrayAsset is automatically extended when you embed an octet-stream file. I just don't get why it seems to be glitching.

My map file contains the expected array of tile numbers and nothing else.

Thanks in advance for any help.

--Jonathan Bruder


« Last Edit: Sat, Apr 3, 2010 by jonathanbruder »