Modify the speed of a running SKAction

前端 未结 2 993
悲哀的现实
悲哀的现实 2021-01-22 09:54

I have this code:

@implementation MyScene {
SKAction *delayAction; 
}
Inside a method:

delayAction = [SKAction waitForDuration:3.0];
[self runAction:[SKAction r         


        
2条回答
  •  一生所求
    2021-01-22 10:27

    I'd do this a different way. Something like this...

    - (void)recursiveActionMethod
    {
        if (some end condition is met) {
            return;
            // this allows you to stop the repeating action.
        }
    
        self.duration -= 0.01;
        // store duration in a property
    
        SKAction *waitAction = [SKAction waitForDuration:self.duration];
        SKAction *theAction = [SKAction doWhatYouWantHere];
        SKAction *recursiveAcion = [SKAction performSelector:@selector(recursiveActionMethod) onTarget:self];
    
        SKAction *sequence = [SKAction sequence:@[waitAction, theAction, recursiveAction]];
        [self runAction:sequence];
    }
    

    This will perform your action and then come back to this function to be run again with a different wait time and again, and again, ...

    You can even stop the sequence by having some end condition that would jump inside the if block and stop the loop.

提交回复
热议问题