Modify the speed of a running SKAction

前端 未结 2 994
悲哀的现实
悲哀的现实 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.

    0 讨论(0)
  • 2021-01-22 10:27

    I am a bit late, but you can instead set the action to SKActionTimingEaseOut. Also this is language native and should work slightly faster. (Though you cannot customize the speed changes) This can be done similarly to this:

    1. yourSKAction.timingMode = SKActionTimingEaseOut;
    0 讨论(0)
提交回复
热议问题