Add the Foreground
Apple Game Frameworks and Technologies — by Tammy Coron (27 / 193)
👈 Set Position, Coordinates, a nd Anchor Points | TOC | Next Steps 👉
You’ve seen how to add an image set and get an SKSpriteNode object initialized, positioned, and added to the scene. You did this with the background. It’s now time to apply that same knowledge and get the foreground added to your scene.
Add the Foreground Images
Before you can add a sprite node with a corresponding image file, you first need to add the images to the project as you did with the background.
In the Project Navigator, select the Assets.xcassets asset catalog.
Once again, launch a Finder window and navigate to the resources folder included with the code resources for this chapter. This time, select the three foreground images:
- foreground_1@1x.png
- foreground_1@2x.png
- foreground_1@3x.png
Drag the foreground images into the Outline View of the Assets.xcassets asset catalog.
Add the Foreground Node
Your next step is to add the code to initialize the sprite node.
Open the GameScene.swift file. In the didMove(to:) method, below the code block that sets up the background node, add the following code:
// Set up foreground
let…