Sawyer05
Sawyer05

Reputation: 1604

Adding Collision Detection to SKTileMapNode

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?

Upvotes: 3

Views: 1309

Answers (1)

Confused
Confused

Reputation: 6288

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.

Upvotes: 2

Related Questions