xcode 一次运行两个 SKActions

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19779608/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 04:15:17  来源:igfitidea点击:

Run two SKActions at once

objective-cxcodesprite-kitskaction

提问by maxhud

I'm using a sequence to run a list of SKActions. What I want to do however, is run an SKAction, then run two at once, then run one in sequence.

我正在使用一个序列来运行 SKAction 列表。然而,我想要做的是运行一个 SKAction,然后一次运行两个,然后依次运行一个。

Here is my code:

这是我的代码:

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];
    }

How can I accomplish this? I'm assuming I can't use a sequence?

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

回答by DogCoffee

Use a group action.

使用集体行动。

From sprite kit programming guide:

来自精灵套件编程指南:

A group action is a collection of actions that all start executing as soon as the group is executed. You use groups when you want actions to be synchronized

组动作是一组动作的集合,一旦组被执行,所有动作都开始执行。当您希望操作同步时使用组

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];

回答by Dave Levy

A example in Swift would be:

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)