Jump to content

Assign tileset to individual layer?


Alastair
 Share

Recommended Posts

Hi everyone,

 

I have a problem which doesn't seem to be covered by the api or examples (that I have found), so hoping someone can help.

 

I have this code, where I am programatically creating a tile map:

  map.addTilesetImage('venicebeach_fg', null, settings.tile.width, settings.tile.height);  map.addTilesetImage('venicebeach_mid', null, settings.tile.width, settings.tile.height);  currentLayer = map.create(    'fg',    settings.world.tile_width,    settings.world.tile_height,    settings.tile.width,    settings.tile.height  );  currentLayer.resizeWorld();

What I am looking for is to be able to say currentLayer.setTilesetImage or something? (http://phaser.io/docs/2.4.4/Phaser.Tilemap.html#create - no param)

 

I don't really want to have to addTilesetImage in a certain order or something, that is not maintainable. The only 'answers' I have seen have said to use Tiled, but that is not an option in this case (please do not suggest that).

 

Thanks for any help :)

 

 

Edit: Just to be clear I plan on creating multiple layers. I'm not necessarily looking to change tilesetImage on the fly while the game is running.

Link to comment
Share on other sites

What's going wrong? You want to associate a tileset with a layer?

 

You don't need to do that. Every tile (starting with your first tileset image) is given a global ID that is 1-based. 0 is empty, and 1 is the first tile, 2 is the second, etc... Once you have a layer, you can call "tilemap.putTile(<GID NUMBER>, x, y, whateverLayer);". Or Tilemap#fill, or whatever. Is that what you're asking?

 

Tileset#create makes a blank layer for you but erases all the other layers. Did you mean createBlankLayer?

 

If you set the tile width and height when you made the Tilemap then you don't need to pass those params to addTilesetImage.

Link to comment
Share on other sites

So I just want to check if I am understanding you correctly:

 

If I do:

map.addTilesetImage('venicebeach_fg', null, settings.tile.width, settings.tile.height);map.addTilesetImage('venicebeach_mid', null, settings.tile.width, settings.tile.height);

And for sake of argument, let's say they both have 5 tiles in them, if I want to use something from 'venicebeach_mid' then the <GID Number> index will be 5 - 10 ?

 

That seems kind of annoying.

 

I would like to be able to do (pseudocode/theoretical):

var layer1 = createLayer(...);var layer2 = createLayer(...);var layer3 = createLayer(...);layer1.use('venicebeach_mid');layer2.use('venicebeach_fg');layer3.use('venicebeach_fg');// Do this a few timesforeach(something something) {  var tileIndex = randomBetween(0, 5)  map.putTile(tileIndex ... layer1)  map.putTile(tileIndex ... layer2)  map.putTile(tileIndex ... layer3)} 

Right now I know how to do all of this apart from assigning an image (tileset) to a layer (I want each tile layer to look different).

 

Sorry if I haven't cleared it up or if I am misunderstanding tile layers.

 

(I probably did mean to use createBlankLayer but still, no param to indicate which tileset image to use)

Link to comment
Share on other sites

That's because tilemap layers don't have an associated tileset; each layer can use any tile from any tileset in the map. Each layer can use tiles from more than one tileset at a time, even.

 

I don't see anything wrong with your pseudo-code except that ".use" would lead to *less* flexibility than the current system provides you. You can still assign whatever tile you want to any layer that you want. Make sense?

 

BTW: is that Hodor? Neat. ( =

Link to comment
Share on other sites

Right, I think I'm with it now. I just wasn't looking at it from the right paradigm.

 

I've updated my addTilesetImage methods to:

map.addTilesetImage('venicebeach_fg', null, settings.tile.width, settings.tile.height, null, null, 0);map.addTilesetImage('venicebeach_mid', null, settings.tile.width, settings.tile.height, null, null, 5);

And it's all working now, now that I understand how it should be used.

 

Thanks for the help!

 

(And yes, that's Hodor ;))

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...