Check if SKAction works

How to check if it has completed SKActionits animation?

I need to check if my action is completed or its action is still in progress. After that, I want to create a boolean to avoid several actions during the main action.

SKAction *lionJumpActionComplete = [lionNode actionForKey:@"lionIsJumping"];
    lionJumpActionComplete = [SKAction sequence: @[lionJumpActionUp, lionJumpActionFly, lionJumpActionDown, lionJumpActionPause]];

    if (lionJumpActionComplete) {
        return;
    }

    [lionNode runAction:lionJumpActionComplete withKey:@"lionIsJumping"];
+4
source share
3 answers

If this is the only action performed on node, you can verify this using:

if (!lionNode.hasActions) { // check if no actions are running on this node
   // action code here
}

Alternatively, you can set a boolean value in the completion block, which is called after the start and end of the action:

[lionNode runAction:[SKAction sequence: @[lionJumpActionUp, lionJumpActionFly, lionJumpActionDown, lionJumpActionPause]] completion:^{
    BOOL isActionCompleted = YES;
}];
+9
source

node. , , , .

    SKAction *animAction = [self actionForKey:@"WalkingZombie"];

    if (animAction) {
        return; // we already have a running animation
    }

    [self runAction:
        [SKAction animateWithTextures:[self walkAnimationFrames]
                         timePerFrame:1.0f/15.0f
                               resize:YES
                              restore:NO]
            withKey:@"WalkingZombie"];
}
0

You need to check if node action is working

therefore in this case

if (![self hasActions]) {
     [self runAction:[self actionForKey:@"ZombieAction"]];
}

maybe better maybe

[self runAction:[SKAction repeatForever:[self actionForKey:@"zombieAction"]]];

who will continue to perform the action forever.

0
source

Source: https://habr.com/ru/post/1527745/


All Articles