slycrel / JSTileMap

TMX Map viewer for SpriteKit
Other
212 stars 34 forks source link

How to add a new tile to a layer, in addition to changing the GID #44

Open thenick775 opened 5 years ago

thenick775 commented 5 years ago

I've been playing around with the setTileGid:at: method and I noticed that it does not add a new node to a layer, it only allows you to change the tile texture/GID. I was wondering the general steps that should be taken in adding a new tile into a layer at runtime, specifically how to perform the operations in removeTileAtCoord: in reverse.

Thank you in advance.

msxnake commented 5 years ago

Its not possible to add new tiles. Just change them. Sorry.

Enviado desde mi iPhone

El 1 dic 2018, a las 7:12, Nicholas VanCise notifications@github.com escribió:

I've been playing around with the setTileGid:at: method and I noticed that it does not add a new node to a layer, it only allows you to change the tileset. I was wondering the general steps that should be taken in adding a new tile into a layer at runtime, specifically how to perform the operations in removeTileAtCoord: in reverse.

Thank you in advance.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

thenick775 commented 5 years ago

If you don't mind me asking, could you explain why? I know that the removeTileAtCoord: method does remove a tile from a specified layer. What I am trying to accomplish is to have a set of tiles in a layer, make them "passable" for my character, and then make them "unpassable" after the character has moved past them.

msxnake commented 5 years ago

To be honest, I think you could do that changing the propierties of the new tiles. No need to add new ones to the layer. Anyway I have abandoned this library in favour of Godot Engine. Sorry.

Enviado desde mi iPad

El 1 dic 2018, a las 22:05, Nicholas VanCise notifications@github.com escribió:

If you don't mind me asking, could you explain why? I know that the removeTileAtCoord: method does remove a tile from a specified layer. What I am trying to accomplish is to have a set of tiles in a layer, make them "passable" for my character, and then make them "unpassable" after the character has moved pat them.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

slycrel commented 5 years ago

Generally speaking, I have used a separate layer with "invisible" tiles that controls if things are passable or not, then would change the layer properties as msxnake mentions rather than adding or removing tiles directly. You could definitely write a function to add a tile. I no longer update JSTileMap, but could poke around in the code a little for you given some time. Check out the function +(id) layerWithTilesetInfo:(NSArray*)tilesets layerInfo:(TMXLayerInfo*)layerInfo mapInfo:(JSTileMap*)mapInfo to see how the layer gets initially built for each tile.