Modify the speed of a running SKAction

风流意气都作罢 提交于 2019-12-02 01:59:42

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.

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;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!