Jump to content

Using multiple tilesets and refering to the tileset for a tile


owen
 Share

Recommended Posts

Hi

I am trying to be organised about my game design with Tiled.  I thought rather than cram everything into 1 tileset I would use a few separate tilesets: One each for platforms, scenery, bad guys, blocks, treasure, etc. I want to then write some JS code based on which tileset the tile belongs to.  For example the collisions could be:

// set up the collisions based on tileset    map.forEach(function (t) {        if (t) {            var ts = t.tileset; // !!!! no such property, what should I use here to get the tileset?            if (ts == "ts-platforms") {                // platforms - impassable from above but passable from below, left, right                t.collideDown = false;                t.collideLeft = false;                t.collideRight = false;            } else if (ts == "ts-solids") {                // solids - impassable from any direction                t.collideDown = true;                t.collideLeft = true;                t.collideUp = true;                t.collideRight = true;            } else if (ts == "ts-scenery") {                // scenery (eg. trees, flowers) - passable from all directions                t.collideDown = false;                t.collideLeft = false;                t.collideRight = false;                t.collideUp = false;            } else if (ts == "ts-treasure") {                // treasure - impassable from any direction                t.collideDown = true;                t.collideLeft = true;                t.collideUp = true;                t.collideRight = true;            } else {                // default - passable from below only                t.collideDown = false;            }        }    }, game, 0, 0, map.width, map.height, layer);

The question is: how do I check in JS code which tileset a tile belongs to?  

 

There does not appear to be a handy "tileset" property for a tile.  Do I have to use layers instead (one tileset per layer)?  Or is it actually bad practice to use seperate tileshes at all - should I stick to cramming it all into one?

 

Thanks

Owen

Link to comment
Share on other sites

UPDATE: I have managed to achieve this using the index property of the tiles.  These seem to be sequential across tilesets.  My tilesets are all 10x10 (indexed 0..99) and the index runs 100..199 for the 2nd set, 200..299 for the 3rd and so on. The trick isknowing which is which and I did that by trial and error. I have 4 of them so I have got it working as follows.

 

// set up the collisions based on tileset    map.forEach(function (t) {        if (t) {                        var tsi = t.index;                               if (tsi >=  0 && tsi < 100) {                 // platforms - impassable from above but passable from below, left, right                t.collideDown = false;                t.collideLeft = false;                t.collideRight = false;            } else if (tsi >= 200 && tsi < 300) {                // blocks - impassable from any direction                t.collideDown = false;                t.collideLeft = false;                t.collideUp = false;                t.collideRight = false;            } else if (tsi >= 100 && tsi < 200) {                // scenery (eg. trees, flowers) - passable from all directions                //            } else if (tsi >= 400 && tsi < 500) {                // treasure - impassable from any direction                t.collideDown = false;                t.collideLeft = false;                t.collideUp = false;                t.collideRight = false;            } else {                // default - passable from below only                t.collideDown = false;            }        }    }, game, 0, 0, map.width, map.height, layer);

If there is a neater/better way then please tell me otherwise I guess I will have to stick with this.

 

Thanks

Owen

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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