Game Development Reference
In-Depth Information
engineExhaust!.hidden = true
}
}
Examining the
hideEngineExhaust()
method, you will see that it does exactly what
it sounds like it will do. It first checks to see whether the
engineExhaust
is visible and
hides it if it is.
Make these changes to the
touchesBegan()
method and add the
re-
moveEngineExhaust()
method to the bottom of the
GameScene
. Once you have
made these changes, run the app again. This time you will notice the exhaust is added to
the
playerNode
each time you tap the screen and will be removed from the
player-
Node
half a second after the last tap. This looks much better. Before closing out this
chapter, make sure the final
touchesBegan()
method looks like the following:
override func touchesBegan(touches: NSSet, withEvent event:
UIEvent) {
if !playerNode!.physicsBody!.dynamic {
playerNode!.physicsBody!.dynamic = true
coreMotionManager.accelerometerUpdateInterval = 0.3
coreMotionManager.startAccelerometerUpdatesToQueue(NSOperationQueue(),
withHandler: {
(data: CMAccelerometerData!, error: NSError!) in
if let constVar = error {
println("There was an error")
}
else {
self.xAxisAcceleration
= CGFloat(data!.acceleration.x)
}
})
}
if self.impulseCount > 0 {
playerNode!.physicsBody!.applyImpulse(CGVectorMake(0.0,
40.0))
impulseCount--
engineExhaust!.hidden = false
NSTimer.scheduledTimerWithTimeInterval(0.5,
target: self,