26

我正在使用一个序列来运行一个 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];
    }

我怎样才能做到这一点?我假设我不能使用序列?

4

2 回答 2

62

使用组操作。

来自精灵套件编程指南:

组操作是一组操作,这些操作在组执行后立即开始执行。当您希望同步操作时使用组

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];
于 2013-11-05T02:16:55.500 回答
5

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)
于 2016-07-13T00:24:56.900 回答