toto88x Posted August 4, 2014 Share Posted August 4, 2014 Hello, I'm doing a platform with tilemaps, and I have a few different levels made with Tiled. In each level, the respawn position for the player is different, and I'd like to store it directly into Tiled. What is the best way to set/retrieve this position? Should I add a specific "respawn" object on my level, then use the "createFromObjects" function, and iterate through the group to find the x and y position of the "respawn" object? Or is there something simpler to do? Thanks! Link to comment Share on other sites More sharing options...
wayfinder Posted August 5, 2014 Share Posted August 5, 2014 The easiest way is probably to create a separate object layer in Tiled with just the one object (player start pos) in it. Link to comment Share on other sites More sharing options...
toto88x Posted August 5, 2014 Author Share Posted August 5, 2014 The easiest way is probably to create a separate object layer in Tiled with just the one object (player start pos) in it. Thanks. And then how do you retrieve the position? The same way that I described in my first post? Edit: something like this? this.respawn = game.add.group();this.map.createFromObjects('Object Layer 1', 2, '', 0, true, false, this.respawn);this.respawn.forEach(function(p){ this.player.reset(p.x, p.y);}, this); Link to comment Share on other sites More sharing options...
toto88x Posted August 8, 2014 Author Share Posted August 8, 2014 Can anyone let me know if there is a better / simpler way to retrieve a respawn position from a tilemap object? See my code just above. Thanks! Link to comment Share on other sites More sharing options...
ssshenkie Posted August 8, 2014 Share Posted August 8, 2014 I'm using your method for my game, works pretty good actually. Why bother even using another method when it works fine right? Link to comment Share on other sites More sharing options...
jloa Posted August 8, 2014 Share Posted August 8, 2014 Can anyone let me know if there is a better / simpler way to retrieve a respawn position from a tilemap object? See my code just above. Thanks! You can write your own method with the same loop as http://docs.phaser.io/Tilemap.js.html#sunlight-1-line-378 but which will only return x/y if object's found. Incase you don't actually need to create the sprite, but rather just know the x/y Link to comment Share on other sites More sharing options...
Recommended Posts