我正在使用序列来运行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];
}
我怎样才能做到这一点?我假设我不能使用序列?
答案 0 :(得分:59)
使用群组操作。
从sprite kit编程指南:
组操作是一组操作,一旦执行完组就会立即执行。如果希望同步操作,可以使用组
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];
答案 1 :(得分:4)
Swift中的一个例子是:
let textLabel = SKLabelNode(text: "Some Text")
let moveTo = CGPointMake(600, 20)
let big = SKAction.scaleTo(3.0, duration: 0.1)
let med = SKAction.scaleTo(1.0, duration: 0.3)
let reduce = SKAction.scaleTo(0.2, duration: 1.0)
let move = SKAction.moveTo(moveTo, duration: 1.0)
let fade = SKAction.fadeOutWithDuration(2.0)
let removeNode = SKAction.removeFromParent()
let group = SKAction.group([fade, reduce])
let sequence = SKAction.sequence([big, med, move, group, removeNode])
self.addChild(textLabel)
textLabel.runAction(sequence)