简体   繁体   English

SKAction序列是否实际等到行动结束?

[英]Does the SKAction sequence actually wait until the action ends?

I have the following code: 我有以下代码:

-(void)aggravatedSeek:(SKSpriteNode *)target{
    _isAggravated = YES;

    SKAction *action = [SKAction runBlock:^{
        double randTime = 0.2;
        NSLog(@"%f", randTime);
        [self moveToSpriteNode:target withTimeInterval:randTime];
    }];

    //SKAction *repeatAction = [SKAction repeatAction:action count:6];
    SKAction *rep = [SKAction sequence:@[action, action, action, action, action]]; //Test Sequence

   [self runAction:rep completion:^{
       [self runAction:blackColorAction];
       _isAggravated = NO;

    }];
}

I want my actions to actually wait until the previous action is done. 我希望我的行动能够等到上一个动作完成。 Meaning, my actions need to be sequenced such that the rep action doesn't repeat the action action until the object FINISHES moving. 意思是,我的行为需要排序,以便在对象完成移动之前, rep动作不会重复action动作。 Currently, it seems like the output immediately runs all the actions and doesn't sequence them like it should. 目前,似乎输出立即运行所有操作,并且不会像它应该那样对它们进行排序。 I have read the documentation and what I have now is what they said to do... 我已经阅读了文档,我现在所拥有的是他们所说的......

The runBlock: action is a fire-once type of action. runBlock: action是一次fire-action类型的操作。 It will run the block exactly once, then the action "ends" immediately afterwards. 它将只运行一次块,然后立即执行“结束”。

What you want is something actions aren't designed to handle. 你想要的是行动不是为了处理而设计的。 They run once, or for a given period of time (duration). 它们运行一次,或者运行一段时间(持续时间)。 They don't, however, run until some arbitrary condition is met - which may be true immediately, may become true eventually or may never become true. 但是,它们不会在满足某些任意条件之前运行 - 这可能是立即成立的,最终可能成为现实或可能永远不会成为现实。 This kind of invalidates all variable timing features actions are capable of (ie linear vs ease scaling of time). 这种无效的所有可变定时特征动作都能够(即线性与容易缩放时间)。

What you can do is to issue the "moveToSpriteNode" movement as an action, and separately check in an update method whether the sprite has arrived at the node. 您可以做的是将“moveToSpriteNode”运动作为动作发出,并分别检查更新方法是否精灵到达节点。 If so, you'd run the next movement action (not using a sequence). 如果是这样,您将运行下一个移动动作(不使用序列)。

More easily you can simply rely on the move action to end meaning that the sprite has arrived at the target node. 更简单的是,您可以简单地依赖移动操作来结束精灵到达目标节点的意义。 Then that would trigger the next move action in the sequence. 然后,这将触发序列中的下一个移动动作。 If you want to run a completion block at each target, just schedule the next move action from within the completion block. 如果要在每个目标上运行完成块,只需在完成块中安排下一个移动操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM