簡體   English   中英

SpriteKit SKAction在調用completitionBlock之前運行多個動作

[英]SpriteKit SKAction run multiple actions before calling a completitionBlock

我可以打電話

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

但是在4個不同的SKNode上執行操作后如何調用一個完成塊?

基本上,我需要在所有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];
}

好的,我不認為有任何內置的或“性感的”方式來實現您所追求的目標,但是至少我認為這是一種可行的解決方案:

您需要一個可變數組,如果按照我的方式編寫代碼,則需要一個私有屬性, 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...
    }
}

看起來您正在嘗試執行以下操作。

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

    SKAction *completion = [SKAction runBlock:^{

    }];

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM