Jump to content

Tilemap with tiled: set and retrieve the respawn position?


toto88x
 Share

Recommended Posts

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

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

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

 Share

  • Recently Browsing   0 members

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