Run a sequence of SKActions with various nodes

I know that I can create SKAction.sequence that will trigger the actions of one node one by one. But how can I do this if I want to make a sequence with different nodes. I would like to do something like this:

  • Run action from node A
  • wait 2 seconds
  • Run action from node B.
+5
source share
1 answer

If both nodes are uniquely named and are children of the same node, you can use runAction:onChildWithName: as shown below:

 SKAction *action = [SKAction sequence: @[[SKAction runAction:[SKAction moveTo:CGPointMake(200.0f, 200.0f) duration:1.0f] onChildWithName:@"NODEA"], [SKAction waitForDuration:2.0f], [SKAction runAction:[SKAction moveTo:CGPointMake(200.0f, 200.0f) duration:1.0f] onChildWithName:@"NODEB"]]]; [parent runAction:action]; 

More generally, you can use runBlock: to do anything, like a step in the SKAction sequence:

 SKAction *action = [SKAction sequence: @[[SKAction runBlock:^{ [nodeA runAction:[SKAction moveTo:CGPointMake(200.0f, 200.0f) duration:1.0f]]; }], [SKAction waitForDuration:2.0f], [SKAction runBlock:^{ [nodeB runAction:[SKAction moveTo:CGPointMake(200.0f, 200.0f) duration:1.0f]]; }]]]; [parent runAction:action]; 
+8
source

Source: https://habr.com/ru/post/1202492/


All Articles