3

What's the recommended way of adding collision detection to an SKTileMapNode for a side scroller?

Say I have a simple tilemap with just one single tile to use as the ground, how can I detect when my player sprite lands on one of the filled ground tiles?

Confused
  • 6,048
  • 6
  • 34
  • 75
Sawyer05
  • 1,604
  • 2
  • 22
  • 37

1 Answers1

2

I'm not entirely sure this will work, but it seems you could add a node to each of a SKTileMapNode's tiles and, based on whatever texture component is on it, give it a physics body appropriately shaped and setup for matching that texture.

Here is someone attempting something like this:

https://forums.developer.apple.com/thread/50043

You don't ask for it, but for greater granularity (eg a tile that's partially covered and needs a sloping physics floor element), it seems this would be the place to start:

https://developer.apple.com/reference/spritekit/sktiledefinition

But I can't find exactly how to know what part of a texture is on any given tile of a tile-map. There must be a way to do this, but I'm just not quite seeing it.

Confused
  • 6,048
  • 6
  • 34
  • 75
  • Thanks @Confused, I'll have a stab at the link you provided. Strange how there's no clear function on setting collision for this. Seems like something that would be a top priority for a tilemap – Sawyer05 Sep 30 '16 at 00:27
  • Yeah, I'm kind of baffled (and confused) that there's not a more thorough design of Tiles with Physics. It seems like the obvious thing to do. It would make it a very powerful and enjoyable tool. I don't even see a way to get touches from tiles, either. I think the designers at apple only considered tilemaps in the simplest sense, and then took an early lunch. – Confused Sep 30 '16 at 00:45
  • I've spent days looking around for alternate solutions but the way you recommended definitely appears to be the only valid way of doing this right now – Sawyer05 Oct 03 '16 at 21:28