Adding a background
We need to create a road for our rabbit to run on and also for it to find the exit of the top hat. In this case, we will follow almost the same steps than we did to add the rabbit, but with a few differences.
Add the background image in a way that is similar to how we added the rabbit's image:
- On the Project Navigator, select the Art group.
- Right-click and select Add Files to "InsideTheHat"….
- Look for the
background.png
file in the7338_01_Resources
folder that you unzipped. Select it and click on Add.
Then, add the following lines to GameScene
before the addChild(rabbit)
line:
// Creating and adding the background to the scene let background = SKSpriteNode(imageNamed: «background») background.anchorPoint = .zero addChild(background) ...
Get Getting Started with SpriteKit 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.