Game Development Reference
In-Depth Information
Just like with Sprite Kit, creating a sequence can create Scene Kit actions. When the code
executes, the actions are run in the order in which the sequence was created, and the se-
quence duration is the sum of all the durations of the actions.
Since you are animating the globeNode , you want the sequence to repeat, and there is
an action that will repeat another action forever. For this you will use the SCNAc-
tion.repeateActionForever: class initializer. Then the final step is to call the
runAction function on the globeNode .
Now when you run your game, you will notice the globe is bouncing as well as rotating
around the y-axis, as shown in Figure 13-5 .
Figure 13-5 . Globe node rotating and bouncing
For the next animation, you will animate the cylinder so that you change the scale.
For the cylinder, you will animate its scale so that it will appear as though the cylinder is
growing and then starting over. However, this time, instead of repeating forever, you will
repeat it only ten times.
let scaleToZero = SCNAction.scaleTo(0.0, duration: 0)
let scaleUp = SCNAction.scaleTo(1.0, duration: 5)
let opacityToZero = SCNAction.fadeOutWithDuration(5)
let sequence = SCNAction.sequence([scaleToZero, scaleUp])
let repeateSequence = SCNAction.repeatAction(sequence,
count: 10)
cylinderNode.runAction(repeateSequence)
Search WWH ::




Custom Search