Game Development Reference
In-Depth Information
override func didSimulatePhysics() {
if playerNode != nil {
playerNode!.physicsBody!.velocity =
CGVectorMake(xAxisAcceleration * 380.0,
playerNode!.physicsBody!.velocity.dy)
if playerNode!.position.x <
-(playerNode!.size.width / 2) {
playerNode!.position = CGPoint(x: size.width
- playerNode!.size.width / 2, y: playerNode!.position.y)
}
else if playerNode!.position.x > size.width {
playerNode!.position =
CGPoint(x: playerNode!.size.width / 2,
y: playerNode!.position.y)
}
}
}
Make these changes, and let's move on to adding the actual transition.
Adding the Transition
Before you can transition to a new scene, you need to have a scene to transition to. The
scene this game needs is a scene that tells the player the score they achieved in the most
recent game and allows them to play a new game.
To create the new scene, select the File New File menu item and then choose iOS
Source Swift File; click the Next button. Make sure you have the SuperSpaceMan
folder selected, name the file MenuScene , and click Create. You will now have an al-
most empty new file named MenuScene.swift . Replace its contents with the contents
of Listing 8-1 .
Listing 8-1 . MenuScene.swift : The SuperSpaceMan MenuScene
import SpriteKit
class MenuScene: SKScene {
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
Search WWH ::




Custom Search