Game Development Reference
In-Depth Information
Before moving on to the collision detection section of this chapter, make sure your modi-
fied GameScene.swift file looks like Listing 3-1 .
Listing 3-1 . GameScene.swift: The SuperSpaceMan Main Modified GameScene
import SpriteKit
class GameScene: SKScene {
let backgroundNode : SKSpriteNode?
var playerNode : SKSpriteNode?
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
override init(size: CGSize) {
super.init(size: size)
physicsWorld.gravity = CGVectorMake(0.0, -2.0);
backgroundColor = SKColor(red: 0.0, green: 0.0,
blue: 0.0, alpha: 1.0)
userInteractionEnabled = true
// 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!.physicsBody =
SKPhysicsBody(circleOfRadius:
playerNode!.size.width / 2)
playerNode!.physicsBody!.dynamic = true
playerNode!.position = CGPoint(x: size.width / 2.0,
y: 80.0)
playerNode!.physicsBody!.linearDamping = 1.0
addChild(playerNode!)
}
Search WWH ::




Custom Search