Configure Physics Bodies Using User Data

To keep the player from leaving the dungeon, you’ll set up physics bodies around the dungeon walls. However, there’s a small problem: tile map nodes do not expose their tiles as nodes, which means you can’t assign physics bodies to the individual tiles. Instead, you’ll use custom user data, more specifically, the userData property of the SKNode class.

The userData property of the SKNode class is an NSMutableDictionary that you can use to store custom values known as “user data.” These custom values can include integers, floats, booleans, and strings. You can either set these up in code or, more conveniently, using the Scene Editor and the Attributes Inspector (there’s a User Data section near the bottom). ...

Get Apple Game Frameworks and Technologies now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.