Author Topic: FlxTilemap: does it support different colors in an image for different objects?  (Read 1982 times)

initials

  • Contributor
  • ****
  • Posts: 378
  • Karma: +0/-0
  • Initials
    • View Profile
    • Initials Blog. Code and other things.
Hello everyone,

I want to ask the help forum first, before I add this to the Flixel 2.5 wishlist thread.

I'm using FlxTilemap to generate a level and it's working great (Going to release Mode: Gravity Remix quite soon!).

Is there are way to use different colored pixels to indicate different items. So for example I use black pixels to indicate level tiles and red pixels indicate enemies, and green pixels indicate items or powerups.

Does that exist already?
I know a solution is just to use DAME or similar, but for me the best level editor would be GIMP with a few different colors to indicate different items.

Also, is there a command in Flixel to determine what version of Flixel you are using. I know this sounds silly but in the Mode example, it comes prepackaged with Flixel in it's ORG folder and there are quite significant changes between whatever one that is using and between that latest one. I spent quite a while unsure why pngToCsv didn't work.
I've looked in the comments of the code and can't find it.

Thanks in advance!

(P.s. Get excited for the Mode: Gravity Remix release)
Initials: Super Lemonade Factory, Super Lemonade Factory Part Two, Above The Clouds, Revvolvver, Four Chambers of the Human Heart

zuperxtreme

  • Contributor
  • ****
  • Posts: 254
  • Karma: +0/-0
    • View Profile
    • Buddah
As far as I know "pngToCSV()" only creates solid and non-solid tiles from a PNG. Poke around that function.
..."without order nothing exists, without chaos nothing evolves"... 
Zoklet.net

Uhfgood

  • Member
  • **
  • Posts: 28
  • Karma: +0/-0
    • View Profile
You'll probably have to code something to read a bitmap in and set your object positions, I don't think a tilemap supports anything like that.  I did write a function that takes a tileset, mapkey (which colors to use for which tile), and the map image itself (using the colors in the mapkey).  It creates a tilemap based on the map image.  If you want I can show you the code, and then you can figure out how to make it represent objects (maybe in your own array) instead of writing to a tilemap.

clifdweller

  • Member
  • **
  • Posts: 12
  • Karma: +0/-0
    • View Profile
Well there is an easy way and a hard way.

easy way - use an individual tile map for each type of entity. It is resource expensive but works. using layers in gimp i overlay each different type of object in different layers(tiles, enemies powerups) then save as separate images then load as separate tilemaps.

hard way- write your own bitmaptocsv(actually not that hard now that I look at it.
         - copy bitmap to csv from flixel tilemap.as
         - replace getpixels with Getpixels32.

var pixelValue:uint = bmd.getPixel32(0, 0);
var alphaValue:uint = pixelValue >> 24 & 0xFF;
var red:uint = pixelValue >> 16 & 0xFF;
var green:uint = pixelValue >> 8 & 0xFF;
var blue:uint = pixelValue & 0xFF;

then just check for RGB values and set p = 0,1,2,3...

then write that value into csv instead of just 1.

not sure if that's exactly what you want. It gets you to the point though where you can create a single tilemap. look around in forums to find out how to go through that to convert certain tiles to enemies, powerups etc..






Uhfgood

  • Member
  • **
  • Posts: 28
  • Karma: +0/-0
    • View Profile
I already wrote one, except it's to create a tilemap rather than a map of "objects" although you could certain create a tilemap specifically for those objects.

Billy

  • Active Member
  • ***
  • Posts: 159
  • Karma: +0/-0
  • Herper of Derps
    • View Profile
    • billy.wenge-murphy.com
Hit the backtick/tilde key (`, the thing next to 1 on the top row, above tab) to bring up the console which will tell you the library version. Alternately you can check FlxG.LIBRARY_MAJOR_VERSION, FlxG.LIBRARY_MINOR_VERSION (I'm not yelling. Constants go in caps ;) )

I believe Mode was originally built on the 1.x branch, and yes, the differences are quite significant!

As for why it's not in there or whether you'll see it in 2.5: maybe not. Depends how many people do it that why. It's kind of an unusual use case. The more common practice is an XML, JSON, plaintext, or other file with coordinates, as entities frequently don't align to the rigid grid of a tilemap.

keptblue

  • Member
  • **
  • Posts: 57
  • Karma: +0/-0
    • View Profile
    • EXTLABS
making a new tilemap for each is creative, but i have a feeling it is a bit resource intensive.

here is my method:

Quote


var _room:FlxTilemap = new FlxTilemap();  // <--- your tile map here

var tilesWidth:int = _room.widthInTiles;
var tilesHeight:int = _room.heightInTiles;

for (var a:int = 0; a < tilesWidth; a++)
{
   for (var b:int = 0; b < tilesHeight; b++)
   {
      switch(_room.getTile(a, b))
      {
         case 6:
            add(new FlxSprite(a * 16, b * 16));   // create a new colored FlxSprite at this location
            _room.setTile(a, b, 0, true);   // set tile to 0 and erase the tile graphic
         break;
      }
   }
}



initials

  • Contributor
  • ****
  • Posts: 378
  • Karma: +0/-0
  • Initials
    • View Profile
    • Initials Blog. Code and other things.
making a new tilemap for each is creative, but i have a feeling it is a bit resource intensive.

here is my method:

Quote


var _room:FlxTilemap = new FlxTilemap();  // <--- your tile map here

var tilesWidth:int = _room.widthInTiles;
var tilesHeight:int = _room.heightInTiles;

for (var a:int = 0; a < tilesWidth; a++)
{
   for (var b:int = 0; b < tilesHeight; b++)
   {
      switch(_room.getTile(a, b))
      {
         case 6:
            add(new FlxSprite(a * 16, b * 16));   // create a new colored FlxSprite at this location
            _room.setTile(a, b, 0, true);   // set tile to 0 and erase the tile graphic
         break;
      }
   }
}



Thanks!
I used this way because Flixel doesn't seem to support overlap with a Sprite and a levelmap.

I'm using it now.
Thanks everyone for your replies.
Initials: Super Lemonade Factory, Super Lemonade Factory Part Two, Above The Clouds, Revvolvver, Four Chambers of the Human Heart

initials

  • Contributor
  • ****
  • Posts: 378
  • Karma: +0/-0
  • Initials
    • View Profile
    • Initials Blog. Code and other things.
By the way, I had to change case 6: to case 1:

Here's the code I used.

Code: [Select]
rampsGrp = new FlxGroup();
add(rampsGrp);

ramps = new FlxTilemap();
ramps.auto = FlxTilemap.ALT;
ramps.loadMap(FlxTilemap.imageToCSV(RampMap, false, 1), FlxTilemap.ImgAuto);
add(ramps);

var tilesWidth:int = ramps.widthInTiles;
var tilesHeight:int = ramps.heightInTiles;

for (var a:int = 0; a < tilesWidth; a++)
{
   for (var b:int = 0; b < tilesHeight; b++)
   {
  //FlashConnect.trace(ramps.getTile(a, b));
  switch(ramps.getTile(a, b))
  {
case 1:
r = new FlxSprite(a*8,b*8,ImgRamp);
add(r);
rampsGrp.add(r);
ramps.setTile(a, b, 0, true);   // set tile to 0 and erase the tile graphic
break;
  }
   }
}
Initials: Super Lemonade Factory, Super Lemonade Factory Part Two, Above The Clouds, Revvolvver, Four Chambers of the Human Heart