Game Development Reference
In-Depth Information
Listing 7-3. Setting up the Animation of the Cloned Nodes
- (void) setupAsteroidAnimationForNode:(SCNNode*)aClone
{
CABasicAnimation *positionAnimation;
SCNVector3 position = aClone.position;
positionAnimation=[CABasicAnimation animationWithKeyPath:@"position"];
positionAnimation.duration=4.0;
positionAnimation.repeatCount=0;
position.z = 0;
positionAnimation.toValue= [NSValue valueWithSCNVector3:position];
[positionAnimation setValue:aClone forKey:@"node"]; //we keep track of the node.
positionAnimation.delegate = self;
[aClone addAnimation:positionAnimation forKey:@"position"];
When the animation is over, the method animationDidStop is called within the delegate, and the node is
removed by calling removeFromParentNode . As stated above, you can retrieve the node from the animation because
it was explicitly added in setupAsteroidAnimationForNode . See Figure 7-3 for the code in action.
-(void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag {
SCNNode* node = [anim valueForKey:@"node"];
[node removeFromParentNode];
}
Figure 7-3. Screenshot from the asteroid sample code. Asteroid mesh courtesy of fl4re Inc. www.fl4re.com
Rendering
Scene Kit offers ways to customize rendering at many levels. However, because rendering deserves a whole chapter
of its own, this section will give just a brief overview.
 
Search WWH ::




Custom Search