1
votes

So with Tiled, I can set Tile Properties directly on a tile before placing it on a map like so:

Setting Tile Properties

This is how I have done collision checking, by setting the collision property to 'true' and then checking the tile properties when moving a sprite.

However, I would like to add a 'teleport' tile. When the player walks on a specific tile, it takes them to a separate location.

The problem I am running into, is that when you set a property on a tile, you only get to set it once, and not on the tile instance. Meaning every tile would have the same teleport location.

Am I overlooking something? Is there a better way to go about doing this in Cocos2d in general?

2

2 Answers

2
votes

You can use the object layer for this. Add an "object" (that's just a rectangle or point in Tiled) to the teleporter tile and use the object's properties to connect two locations together.

When you load the map you could walk over all objects to find the connecting objects. Then you know the two tile locations of the teleporter end points which you could store in a teleportation array. Every time your player moves to a new tile, check the teleportation array to see if the player is on one of the teleportation fields, and if he is, move him to the other teleportation tile.

Of course you could also check intersection with the object (rectangle) but since there's a chance that you might accidentally create an object (rectangle) that spans multiple tiles it seems more reliable to check these objects before the game starts.

1
votes

Well this probably is the best way but it's what I've done. You could create a meta layer and have separate tiles for each teleporting pad. So when you check if the player is on teleportingpad1 you set the players location to receiverPad1 (which could be another tile, object in tiled, or just a point you set when you check for collisions). And you would just make another one e.g. teleportingpad2, teleportingpad3, etc. for more pads.