Game Development Reference
In-Depth Information
let frame2 = textureAtlas.textureNamed("BlackHole2")
let frame3 = textureAtlas.textureNamed("BlackHole3")
let frame4 = textureAtlas.textureNamed("BlackHole4")
let blackHoleTextures = [frame0, frame1, frame2, frame3,
frame4]
Once you have examined this code, add it to the top of the addBlackHolesToFore-
ground() method immediately after the creation of the textureAtlas .
Now, all you have to do to animate the black holes is to create a new action using the
SKAction.animateWithTextures() method, passing it the array of textures and
the time, in seconds, each frame is to be displayed. Take a look at the following lines:
let animateAction =
SKAction.animateWithTextures(blackHoleTextures,
timePerFrame: 0.2)
let rotateAction
= SKAction.repeatActionForever(animateAction)
The first line creates an action that will display each texture in the textureAtlas array
for 2/10ths of a second. To make the black hole nodes animate forever, the second line
creates another action that will perform the animation action forever. To see your new an-
imation in action, copy all of this code to the top of the addBlackHolesToFore-
ground() method immediately after the blackHoleTextures array and then add
the following line, which will run the action, right before you add each black-
HoleNode to the scene:
blackHoleNode.runAction(rotateAction)
When you have made all of these changes to the addBlackHolesToForeground()
method, the new method will look like the following:
func addBlackHolesToForeground() {
let textureAtlas = SKTextureAtlas(named:
"sprites.atlas")
let frame0 = textureAtlas.textureNamed("BlackHole0")
let frame1 = textureAtlas.textureNamed("BlackHole1")
let frame2 = textureAtlas.textureNamed("BlackHole2")
let frame3 = textureAtlas.textureNamed("BlackHole3")
let frame4 = textureAtlas.textureNamed("BlackHole4")
Search WWH ::




Custom Search