nemoDreamer Posted January 2, 2015 Share Posted January 2, 2015 Take the following code: preload: function() { this.load.tilemap(this.level_key, 'assets/levels/test_01.json', null, Phaser.Tilemap.TILED_JSON); this.load.atlasJSONHash(this.atlas_key, 'assets/images/tiles.png', 'assets/images/tiles.json'); }, // [...] // These called from `create`: createMap: function() { // Add tilemap this.map = this.game.add.tilemap(this.level_key); // Attach tiles this.tileset = this.map.addTilesetImage(this.tiled_tileset_key, this.atlas_key); // Create layers // [...] this.charactersLayer = this.map.createLayer('Characters'); }, createPlayer: function() { // Find player tile var player_frame = this.game.cache.getFrameByName(this.atlas_key, this.texture_packer_keys.player); var player_index = player_frame.index + 1; // atlas 0-based, but tilemap tileset is 1-based var player_tile = this.map.searchTileIndex(player_index, 0, false, 'Characters'); // Create and center player sprite this.player = this.game.add.sprite(player_tile.worldX, player_tile.worldY, this.atlas_key, this.texture_packer_keys.player); // Remove placeholder tile this.map.removeTile(player_tile.x, player_tile.y, 'Characters'); // [...] },Is there a simpler (built-in) way of retrieving a tile from a tilemap using its atlas frame name?I've scoured the `this.map` Tilemap object, and can't find any reference to the original atlas names, since it seems that `this.map.addTilesetImage(...)` just carries over indexes? Additional question: would I avoid this issue by using an Object layer for my player placeholder? Link to comment Share on other sites More sharing options...
lexfrost Posted January 11, 2016 Share Posted January 11, 2016 Is there another solution for this? I'm currently using the below where 'tilesetimage1' is a preloaded image and I'd like to use an image from an atlas for the tilemap this.tilemap.addTilesetImage('tilemap','tilesetImage1'); Thanks Link to comment Share on other sites More sharing options...
Babsobar Posted November 16, 2016 Share Posted November 16, 2016 Sorry for bumping such an old thread but I'm interested in this as well, it would be nice to be able to load the atlas as a tilemap and use the atlas names instead of indexes for the tilelayer.swapTile, tilelayer,putTile..etc Has anyone managed this? Link to comment Share on other sites More sharing options...
Recommended Posts