Control Render Order with Z-Position
When you add nodes to the scene, you’re building a node tree, which you briefly read about in Chapter 1, Creating Scenes with Sprites and Nodes. The order in which you add a node to the scene determines how it’s rendered. In this case, you added the background node last, which places it on top of the other nodes.
Here’s how it works:
- The scene renders itself, clearing its contents to its background color.
- The scene renders the foreground node, the player node, and finally, the background node.
You could build your scenes with this process in mind, but that can get complicated as you add and remove nodes. Luckily, you’re able to change how things render by using a node’s z-position. You can think of the z-position ...
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.