2

I am using SKTiled.

The SKTileLayer.tileAt(0,0) function returns the tile at a CGPoint. The SKTileLayer.pointForCoordinate(coord: CGPoint) does the same.

All I want is to get a Tile on the Grid (0,0) and not tiles on CGPoints. That would be the first Grid in the map. How can I get the tiles in that way?

Edit: tileAt(0,0) returns the first Grid but if I want to change the Player position to tileAt(0,0) it ist not the real position.

Lirf
  • 111
  • 12

1 Answers1

2

That's a great framework, you can use the method that returns a tile coordinate for a given point in the layer:

SKTileLayer.coordinateForPoint(<#T##TiledLayerObject#>)

You can find more details to the framework official documentation here

You can also get the tile following the autocompletion as:

enter image description here

As you can see it return a SKTile

Alessandro Ornano
  • 34,887
  • 11
  • 106
  • 133
  • Okay this works, but why I have to addChild(player) to the Layers to get work?? – Lirf Feb 12 '17 at 16:44
  • No, it's not necessary, you should pay attention to the `zPosition`. To this purpose always to the [docs](https://mfessenden.github.io/SKTiled/Classes/SKTilemap.html#/s:vC7SKTiled9SKTilemap13lastZPositionV12CoreGraphics7CGFloat) you can find a useful var called `lastZposition` – Alessandro Ornano Feb 12 '17 at 16:52
  • If I don't do 'SKTileLayer.addChild(Player)' I get not the right position for the player node.. Whatever, do you know how to speed up the creation of the tile map? 1,6 seconds on a small map.. – Lirf Feb 12 '17 at 16:57
  • 1
    Don't forget that layers derived from `SKNode` so , to obtain your position you should make something like: `nodeWhereIsYourLayer.convert(yourCGPoint, to: nodeDestinationWhereIsYourPlayer)` – Alessandro Ornano Feb 12 '17 at 17:07
  • The tile map speed is involved by many factors: if you have many layers in a TMX map for example 3200x3200, there are many tiles/objects to render, I've a big map for example that need 2.290sec – Alessandro Ornano Feb 12 '17 at 17:12