ios - Changing Background Moving Speed -
in gamescene background moving horizontally it's working fine want move background slow , fast according score increasing, proceed way nstimeinterval changing nothing can see change background moving slow , fast going normal, if way wrong me please.
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]]]; (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];
try code:
it directly multiply animation time score _move*__gamescore
, can provide intalize value _move
variable.
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]]]; (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];
Comments
Post a Comment