Tilemaps with different tilesets

159 views
Skip to first unread message

Roméo Labonté

unread,
Feb 19, 2015, 2:19:26 PM2/19/15
to haxef...@googlegroups.com
Mornin'!

I've been bashing my head against this problem for a while now: I'm not able to load two FlxTilemaps with different tilesets. I am loading a Tiled TMX file using modified code from the example:

[... other unrelated code ...]

for (tl in layers) {
var tileLayer:TiledLayer = tl;
var tileSheetName:String = tileLayer.properties.get("tileset");
if (tileSheetName == null) {
throw "'tileset' property not defined for the '" + tileLayer.name + "' layer. Please add the property to the layer.";
}
var tilemap:FlxTilemap = new FlxTilemap();
tilemap.widthInTiles = width;
tilemap.heightInTiles = height;
tilemap.loadMap(tileLayer.tileArray, tilesetPath + tileSheetName, 24, 24, 0, 1, 1, 1);
tilemap.cameras = [FlxG.camera];
if (tileLayer.properties.contains("parallax")) {
tilemap.scrollFactor.x = tilemap.scrollFactor.y = Std.parseFloat(tileLayer.properties.get("parallax"));
}
if (tileLayer.properties.contains("spikes")) {
spikeLayer = tilemap;
}
if (tileLayer.properties.contains("background")) {
background.add(tilemap);
} else {
foreground.add(tilemap);
}
if (tileLayer.properties.contains("collide")) {
if (collidableTileLayers == null) {
collidableTileLayers = new Array<FlxTilemap>();
}
collidableTileLayers.push(tilemap);
}
}

[... other unrelated code ...]

Tracing out at various point in this code tells me that everything is going well. It even gets added properly to the correct group (in another class).

Here's what it looks like in Tiled:

The "platforms" and background are on two different tilesets. This is what it looks like in-game:

I've exhausted my ideas. Does anyone have an idea?

Claude Jr Labonté Lefebvre

unread,
Feb 21, 2015, 7:39:23 PM2/21/15
to
Please send help I'm running into the same problem

( ͡° ͜ʖ ͡°)

Nazywam

unread,
Feb 22, 2015, 6:30:13 AM2/22/15
to haxef...@googlegroups.com
Have You tried tracing each FlxTilemap to see where the problem lies? 
You could also try reordering layers in Tiled or leaving just one layer.
If it helps, here is how I'm doing it.

Roméo Labonté

unread,
Feb 22, 2015, 12:15:26 PM2/22/15
to haxef...@googlegroups.com
Tracing out the FlxTilemaps displays all the tilemaps correctly, with the correct tileset. They are even added to the group in which they belong! thanks for the sample, I'll look into it!

Jacob Vann

unread,
Mar 2, 2015, 6:20:52 PM3/2/15
to haxef...@googlegroups.com
I ran into this problem as well.  The first tile layer loaded is the one whose tileset "sticks".  The other ones just show up blank.  I verified with traces that the subsequent layers are loading with the correct tileset image, but they do not show up.  If I set them to use the same tile image as the first tile layer, they show up.  But I would prefer to keep foreground and background tiles to separate tile images if possible.

I even tried forcing the new tile layers to redraw but nothing.    It looks like the tile layers are getting set to the correct values, but they are not drawing.  Is there some undocumented limitation in FlxTilemap to only use one image for tiles?

-Jacob

Jacob Vann

unread,
Mar 2, 2015, 9:50:10 PM3/2/15
to haxef...@googlegroups.com
I think I had a breakthrough with this issue.

It looks like the tile indexes aren't being set like you would expect.  For instance, let's say you have 2 tilesets:

Tileset 1: 64 Tiles
Tileset 2: 8 Tiles

In Tiled, The tilelayers using Tileset 1 will have indexes from 1-64, and those from Tileset 2 will have indexes from 65 to 72.  But, Haxeflixel is expecting indexes that start at 0 (by default) and go to (number of frames in your image  - 1).  You can use the StartingIndex parameter in the LoadMap function to offset this.  So, for the above example, if you passed 65 to the starting index parameter when loading the tile layer from Tileset 2, it displays the tiles!

For now, looks like you can hardcode the offsets and pass them to the StartingIndex parameter of LoadMap... I'm sure there is a more elegant solution, but this is enough to get you started.

You can look in the actual map data of the tiled map file (must save as CSV) to see that tiled is saving the tile indexes like this, so it is an effect of Tiled, not Haxeflixel.

-Jacob

On Thursday, February 19, 2015 at 1:19:26 PM UTC-6, Roméo Labonté wrote:
Reply all
Reply to author
Forward
0 new messages