SpriteKit SKAction在调用completitionBlock之前运行多个动作

时间:2014-02-20 14:37:55

标签: ios iphone sprite-kit

我可以打电话

- (void)runAction:(SKAction *)action completion:(void (^)(void))block

但是如何在4个不同的SKNode s上运行操作后调用一个完成块?

基本上我需要的是在所有4个SKNode上调用此方法后执行一些操作

- (void)rotateToSquareIndex:(SquareIndex)squareIndex
{
    self.squareIndex = squareIndex;
    int index        = self.index;
    SKAction * action;
    switch (squareIndex)
    {
        case indexTopLeft:
            action = [SKAction moveTo:CGPointMake(16.f, 16.f) duration:.3];
            index -= 1;
            break;
        case indexTopRight:
            action = [SKAction moveTo:CGPointMake(48.f, 16.f) duration:.3];
            index += 10;
            break;
        case indexBottomRight:
            action = [SKAction moveTo:CGPointMake(48.f, 48.f) duration:.3];
            index += 1;
            break;
        case indexBottomLeft:
            action = [SKAction moveTo:CGPointMake(16.f, 48.f) duration:.3];
            index -= 10;
            break;
        default:
            break;
    }
    self.index = index;

    [self runAction:action];
}

2 个答案:

答案 0 :(得分:0)

好吧,我认为没有任何内置或“性感”的方式来实现你所追求的目标,但这至少是我认为应该有效的解决方案:

如果你按照我的方式编写代码,你需要一个可变数组,一个私有属性,squareIndexesRotated

- (void)rotateToSquareIndex:(SquareIndex)squareIndex
{
    self.squareIndex = squareIndex;
    int index        = self.index;
    NSNumber *indexNumber = [NSNumber numberWithInt:index];
    if (![self.squareIndexesRotated containsObject:indexNumber]){
        [self.squareIndexesRotated addObject:indexNumber];
    }

    // your action + switch stuff

    if ([self.squareIndexesRotated count] == 4){
        // Do whatever you want here...
    }
}

答案 1 :(得分:0)

看起来你正试图做这样的事情。

    YourAction = [SKAction moveTo:CGPointMake(100, 280)duration:5.0];

    SKAction *completion = [SKAction runBlock:^{

    }];

    SKAction *sequence = [SKAction sequence:@[ YourActions ,etc... ]];
    [YourNode runAction:sequence];