[英]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: 我试过了:
moveDown
as an instance variable. 将初始moveDown
作为实例变量。 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.