我正在使用一个序列来运行一个SKActions列表。然而,我想要做的是运行一个SKAction,然后一次运行两个,然后依次运行一个。
这是我的代码:
SKNode *ballNode = [self childNodeWithName:@"ball"]; if (ballNode != Nil){ ballNode.name = nil; SKAction *delay = [SKAction waitForDuration:3]; SKAction *scale = [SKAction scaleTo:0 duration:1]; SKAction *fadeOut = [SKAction fadeOutWithDuration:1]; SKAction *remove = [SKAction removeFromParent]; //put actions in sequence SKAction *moveSequence = [SKAction sequence:@[delay,(run scale and fadeout at the same time),remove]]; //run action from node (child of SKLabelNode) [ballNode runAction:moveSequence]; }
我该如何做到这一点?我假设我不能使用序列?
解决方法
使用组动作。
从精灵套件编程指南:
组操作是一旦执行组即可开始执行的操作的集合。当您希望操作同步时,可以使用组
SKSpriteNode *wheel = (SKSpriteNode*)[self childNodeWithName:@"wheel"]; CGFloat circumference = wheel.size.height * M_PI; SKAction *oneRevolution = [SKAction rotateByAngle:-M_PI*2 duration:2.0]; SKAction *moveRight = [SKAction moveByX:circumference y:0 duration:2.0]; SKAction *group = [SKAction group:@[oneRevolution,moveRight]]; [wheel runAction:group];