slycrel / JSTileMap

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

How to get x,y of a tile in world coordinates #24

Closed TazmanNZL closed 9 years ago

TazmanNZL commented 9 years ago

Heya,

Is there a way of finding what the x and y position is of a tile in world co-ordinates?

I can get the tile coordinates in the map itself but I don't know how to convert this to world x and y position. (What is the position of the tile in the scene?)

slycrel commented 9 years ago

It should be the same way you convert a point to any other node, though it's been a while since I've done that. have a look here.

http://stackoverflow.com/questions/20746299/how-to-convert-coordinates-of-one-sknode-to-another-sknode

On Tue, Dec 9, 2014 at 12:09 PM, TazmanNZL notifications@github.com wrote:

Heya,

Is there a way of finding what the x and y position is of a tile in world co-ordinates?

I can get the tile coordinates in the map itself but I don't know how to convert this to world x and y position. (What is the position of the tile in the scene?)

— Reply to this email directly or view it on GitHub https://github.com/slycrel/JSTileMap/issues/24.

TazmanNZL commented 9 years ago

I tried that but does' that just set (0,0) on the node? Cause it's not giving me the node's position in the scene.

SKNode tileNode = [[self.map layerNamed:theLayer.name] nodeAtPoint:tileCoord]; SKNode testNode = [SKNode node]; [testNode convertPoint:CGPointMake(0, 0) fromNode:tileNode];

Not sure if I am doing it right but I'm getting (0,0) back for testNode's position ??

slycrel commented 9 years ago

Hi @TazmanNZL,

I hope you have figured out this issue. An example on top of the above stack overflow link of what you describe could be done similar to this:

CGPoint convertedPosition = [yourGameScene convertPoint:theSprite.position fromNode:yourSprite];