在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];
我認爲你需要將'_gameScore'直接乘以'_move',並且爲什麼要乘以'backgroundTexture.size.width'。 – 2014-09-10 14:33:58
可以如何編輯代碼? – anjani 2014-09-10 14:38:08
,因爲它的時間間隔寬度水平移動 – anjani 2014-09-10 14:46:05