2

Im trying to animate multiple SCNNodes using the SCNAction class to run concurrently but I'm having a hard time figuring it out. I have a feeling that it might not be possible though but it doesn't hurt to throw the question out there and see if anyone has an answer.

For example:

Lets say I made

SCNAction *move = [SCNAction moveTo:SCNVector3Make(10.0,0.0,10.0) duration:5.0];

and wanted to run two nodes concurrently to the same spot

[nodeOne runAction:move];
[nodeTwo runAction:move];

When I do this nodeOne would just run the action and nodeTwo won't even run after nodeOne. Is there a way to make nodeOne and nodeTwo move at the same time?

side note: I'm doing this in the -(void) viewDidLoad, should i be using viewDidAppear to make this happen?

Chris
  • 21
  • 4
  • When I tried a similar example, both nodes did converge to the same point concurrently. Will take a look if you post more of your code. – sambro May 02 '15 at 14:54
  • For some reason when I try to do run nodeOne and nodeTwo using the syntax above and what you gave it doesn't work for me. However, I figured out that by using a foreach loop and putting node one and two into a mutable array I was able to apply multiple SCNActions to them and have them run concurrently! Thank you for your answer though! – Chris May 03 '15 at 23:07

1 Answers1

0

Here is the actual code from my example (from the Game Template).

- (void)viewDidLoad
{
    [super viewDidLoad];

    // create a new scene
    SCNScene *scene = [SCNScene scene];

    // create and add a camera to the scene
    SCNNode *cameraNode = [SCNNode node];
    cameraNode.camera = [SCNCamera camera];
    [scene.rootNode addChildNode:cameraNode];

    // place the camera
    cameraNode.position = SCNVector3Make(0, 30, 90);

    // retrieve the ship node
    SCNNode *box1 =  [SCNNode node];
    SCNNode *box2 =  [SCNNode node];

    box1.geometry = [SCNBox boxWithWidth:85 height:5 length:5 chamferRadius:0];
    box1.position =  SCNVector3Make(-10, 30, -10);

    box2.geometry = [SCNBox boxWithWidth:80 height:10 length:10 chamferRadius:0];
    box2.position =  SCNVector3Make(0, 10, 5);

    [scene.rootNode addChildNode:box1];
    [scene.rootNode addChildNode:box2];

    SCNAction *move = [SCNAction moveTo:SCNVector3Make(10.0,30.0,-10.0) duration:5.0];

    [box1 runAction:move];
    [box2 runAction:move];

    // retrieve the SCNView
    SCNView *scnView = (SCNView *)self.view;

    // set the scene to the view
    scnView.scene = scene;

    // allows the user to manipulate the camera
    scnView.allowsCameraControl = NO;

    // show statistics such as fps and timing information
    scnView.showsStatistics = YES;

    // configure the view
    scnView.backgroundColor = [UIColor blackColor];

}

The boxes converge nicely. Isn't this the effect you are looking for?

sambro
  • 816
  • 5
  • 12