Game Development Reference
In-Depth Information
super.init(size: size)
backgroundColor = SKColor(red: 0.0, green: 0.0,
blue: 0.0, alpha: 1.0)
// adding the background
backgroundNode = SKSpriteNode(imageNamed:
"Background")
backgroundNode!.anchorPoint = CGPoint(x: 0.5, y:
0.0)
backgroundNode!.position = CGPoint(x: size.width
/ 2.0, y: 0.0)
addChild(backgroundNode!)
// add the player
playerNode = SKSpriteNode(imageNamed: "Player")
playerNode!.position = CGPoint(x: size.width / 2.0,
y: 80.0)
addChild(playerNode!)
}
}
Summary
In this chapter you learned what Sprite Kit is and how you create a new Sprite Kit game
using Xcode. You then dove in and created the beginnings of a Sprite Kit game starting
from scratch. You learned about SKNode s and their subclasses, and you used an SKS-
priteNode to add both a background node and a player node.
In the next chapter, you will dig a little deeper into Sprite Kit and discuss the details of the
SKScene , including the coordinate system and anchor points. You will also look at how
a scene's node tree is constructed.
Search WWH ::




Custom Search