修改正在运行的SKAction的速度 [英] Modify the speed of a running SKAction

查看:129
本文介绍了修改正在运行的SKAction的速度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这段代码:

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

delayAction = [SKAction waitForDuration:3.0];
[self runAction:[SKAction repeatActionForever: [SKAction sequence:
                                                @[delayAction, [SKAction ...]]]]]
                                                  withKey:@"myKey"];

然后我希望减少加班时间。 (这个方法在更新时被调用:)
所以我试过:

Then i want to decrease duration overtime. (This method is called on update:) So i tried:

    - (void)updateVelocity
{
    NSLog(@"duration:%f",delayAction.duration);
    delayAction.duration = delayAction.duration - 0.001;
}

我得到:

2014-04-04 11:45:05.781 FlyFish[5409:60b] duration:1.300000
2014-04-04 11:45:05.785 FlyFish[5409:60b] duration:1.299000
2014-04-04 11:45:05.800 FlyFish[5409:60b] duration:1.298000
2014-04-04 11:45:05.816 FlyFish[5409:60b] duration:1.297000

这似乎不错,但我的[SKAction ...]在3秒后仍然继续重复。

Which seems good, but my [SKAction ...] still continues repeating after 3 seconds.

推荐答案

我会以不同的方式做到这一点。这样的东西...

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, ...

您甚至可以通过在if块内跳入一些结束条件来停止序列并停止循环。

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

这篇关于修改正在运行的SKAction的速度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆