Game Development Reference
In-Depth Information
There is one last change I would like to make. If you have had the player run into a black
hole recently, you will know that it is a bit anticlimactic. I want to add a visual indicator
that shows the player is dead. A simple way to do this is to use a colorize action. A color-
ize action will blend a second color into an SKNode over a specified interval. An ex-
ample creation of colorizeAction is shown here:
SKAction.colorizeWithColor(UIColor.redColor(),
colorBlendFactor: 0.5, duration: 1)
This action, when run on an SKNode , will blend a red color with a blend factor of 0.5
over a period of 1 second. This is similar to what I would like to apply to the player-
Node when it comes into contact with a black hole. Take a look at the last two lines of
this modified didBeginContact 's method:
func didBeginContact(contact: SKPhysicsContact!) {
var nodeB = contact!.bodyB!.node!
if nodeB.name == "POWER_UP_ORB" {
impulseCount++
nodeB.removeFromParent()
}
else if nodeB.name == "BLACK_HOLE" {
playerNode!.physicsBody!.contactTestBitMask = 0
impulseCount = 0
var colorizeAction
= SKAction.colorizeWithColor(UIColor.redColor(),
colorBlendFactor: 1.0, duration: 1)
playerNode!.runAction(colorizeAction)
}
}
These two lines create a colorize action that will fully blend a red color to the player-
Node over a period of one second whenever the player runs into a black hole. Make these
changes and run the application one more time. When you run it this time, be sure to run
the player into a black hole. Notice how, when he does, he will slowly turn red and fall to
the planet's surface—much better.
Summary
Search WWH ::




Custom Search