Jump to content

one map, multiple tilesets


neon
 Share

Recommended Posts

Hey,

 

I was just wondering. In the docs under "addTilesetImage" there is written that one can use multiple tilesets for the same map. But how do you select which tileset is currently in use? I can't find any function and there is no example with multiple tilesets.

Everytime i load two or more tileset images, only tiles from the first are used.

 

There is a thread about the same topic, but without an answer:

http://www.html5gamedevs.com/topic/8266-use-multiple-tileset-images-in-one-tilemap/

 

So is there a way to use multiple tilesets like it's written in the docs?

 

Edit:

There is an example with multiple tilesets: http://examples.phaser.io/_site/view_full.html?d=tilemaps&f=create+from+objects.js&t=create%20from%20objects but i uses tiled json. I need to specify the map dynamically in code

 

Edit2:

Ok, i probably got that you can't have multiple tilesets per map. You can have only one set per layer. For changing tileset I needed to clear the cache after every change with resetTilesetCache.

Link to comment
Share on other sites

  • 10 months later...
  • 10 months later...
On 2/7/2015 at 4:47 AM, neon said:

Hey,

 

I was just wondering. In the docs under "addTilesetImage" there is written that one can use multiple tilesets for the same map. But how do you select which tileset is currently in use? I can't find any function and there is no example with multiple tilesets.

Everytime i load two or more tileset images, only tiles from the first are used.

 

There is a thread about the same topic, but without an answer:

http://www.html5gamedevs.com/topic/8266-use-multiple-tileset-images-in-one-tilemap/

 

So is there a way to use multiple tilesets like it's written in the docs?

 

Edit:

There is an example with multiple tilesets: http://examples.phaser.io/_site/view_full.html?d=tilemaps&f=create+from+objects.js&t=create%20from%20objects but i uses tiled json. I need to specify the map dynamically in code

 

Edit2:

Ok, i probably got that you can't have multiple tilesets per map. You can have only one set per layer. For changing tileset I needed to clear the cache after every change with resetTilesetCache.

I just found out you need to change map.tiles array. Which is used for drawing tile into tile map. Here is my code for doing that. You need to do it every time you change your tile set.

There is one problem  thought, i think you need to clear it tile set cache too

 var changeMapTileSetArray = function(tileSetKey){
        map.tiles = [];
        var tileSet = Constant.TILE_SET_DICT[tileSetKey];
        var currentTileSetId = map.getTilesetIndex(tileSetKey);
        for(var i = 0;i<tileSet.tileList.length;i++){
            map.tiles.push([tileSet.tileList[i].x,tileSet.tileList[i].y,currentTileSetId]);
        }
    };

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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