简体   繁体   English

iOS在重复动作中更改SKAction速度

[英]iOS Changing SKAction speed in repeating action

I've read in a few placing that changing the speed variable of an SKAction will change the speed; 我已经读过几篇文章了,改变SKAction的speed变量会改变速度。 however, that doesn't seem to be working for me. 但是,这似乎不适用于我。

- (void)startAnimating {
    SKAction *moveDown = [SKAction moveByX:0 y:-[CAUtilities screenSize].height duration:self.animationDuration];
    [self setMoveDownAction:[SKAction repeatActionForever:moveDown]];
    [self runAction:self.moveDownAction];
}

- (void)incAnimationSpeedBy:(CGFloat)aFloat {
    self.moveDownAction.speed += 0.5;
    NSLog(@"%f", self.moveDownAction.speed);
}

The actual value of self.moveDownAction.speed changes as seen in the NSLog call, but the actual animation doesn't change. NSLog调用所示, self.moveDownAction.speed的实际值self.moveDownAction.speed更改,但实际动画不会更改。

I have incAnimationSpeedBy: being called when the screen is tapped, so using a SKAction sequence with a runBlock won't work for my needs. 我有incAnimationSpeedBy:轻按屏幕时会被调用,因此将SKAction序列与runBlock配合使用将无法满足我的需求。

I've tried: 我试过了:

  • Having the initial moveDown as an instance variable. 将初始moveDown作为实例变量。
  • Having the repeat forever action as an instance variable (seen above). 将永远重复动作作为实例变量(如上所示)。
  • Changing the duration property rather than speed . 更改duration属性而不是speed

Any help is appreciated, thanks. 任何帮助表示赞赏,谢谢。

The problem was I was trying to change the speed on the different SKAction objects when I should have been changing the speed on the parent SKSpriteNode . 问题是我本该在父SKSpriteNode上更改速度时,尝试更改不同SKAction对象上的速度。

- (void)startAnimating {
    SKAction *moveDown = [SKAction moveByX:0 y:-[CAUtilities screenSize].height duration:3.0];
    [self runAction:[SKAction repeatActionForever:moveDown]];
}

- (void)incAnimationSpeedBy:(CGFloat)aFloat {
    if (self.speed + aFloat < kMaxSpeed)
        self.speed += aFloat;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM