在gameScene背景水平移动它工作正常,但我想根据分数增加慢速和快速移动背景,我继续这种方式与nstimeinterval改变但没有什么我可以看到改变背景移动缓慢和快速它正常,如果这种方式有问题请有人帮帮我。
SKTexture *backgroundTexture = [SKTexture textureWithImageNamed:@"background10"];
NSTimeInterval _move;
int _gameScore;
if (_gameScore>=5) {
_move =0.09;
}else{
_move = 0.02;
}
SKAction *movBg = [SKAction moveByX:-backgroundTexture.size.width*2 y:0 duration:_move*backgroundTexture.size.width];
SKAction *resetBg =[SKAction moveByX:backgroundTexture.size.width*2 y:0 duration:0];
SKAction *movebackgroundforever =[SKAction repeatActionForever:[SKAction sequence:@[movBg,resetBg]]];
for (int i= 0; i<2 + self.frame.size.width/(backgroundTexture.size.width*2 ); ++i) {
SKSpriteNode* sprite = [SKSpriteNode spriteNodeWithTexture:backgroundTexture];
[sprite setScale:1.0];
sprite.zPosition = -20;
sprite.anchorPoint = CGPointZero;
sprite.position = CGPointMake(i* sprite.size.width, 0);
[sprite runAction:movebackgroundforever];
[_bgLayer addChild:sprite];
答案 0 :(得分:0)
试试这段代码:
它会直接将动画时间与得分_move*__gameScore
相乘,您还可以为_move
变量提供一些intalize值。
SKTexture *backgroundTexture = [SKTexture textureWithImageNamed:@"background10"];
NSTimeInterval _move;
SKAction *movBg = [SKAction moveByX:-backgroundTexture.size.width*2 y:0 duration:_move*__gameScore];
SKAction *resetBg =[SKAction moveByX:backgroundTexture.size.width*2 y:0 duration:0];
SKAction *movebackgroundforever =[SKAction repeatActionForever:[SKAction sequence:@[movBg,resetBg]]];
for (int i= 0; i<2 + self.frame.size.width/(backgroundTexture.size.width*2 ); ++i) {
SKSpriteNode* sprite = [SKSpriteNode spriteNodeWithTexture:backgroundTexture];
[sprite setScale:1.0];
sprite.zPosition = -20;
sprite.anchorPoint = CGPointZero;
sprite.position = CGPointMake(i* sprite.size.width, 0);
[sprite runAction:movebackgroundforever];
[_bgLayer addChild:sprite];