I need make active background which consists of 2 CCSprites which moves successive. But at the same time between CCSprites appear a little interval. How fix it?
Some init code:
sprite1 = [sprites objectAtIndex:0];
[sprite2 setPosition:ccp(240.0,self.position.y)];
sprite2 = [sprites objectAtIndex:1];
[sprite2 setPosition:ccp(720.0,self.position.y)];
[self addChild:sprite1 z:0];
[self addChild:sprite2 z:1];
[self schedule:@selector(update) interval:1/60.0];
This is the code, which move sprites:
-(void)update{
if (sprite1.position.x<=-239.0) {
[sprite1 setPosition:ccp(720.0,self.position.y)];
flag = false;
}else{
if (sprite2.position.x<=-239.0) {
[sprite2 setPosition:ccp(720.0,self.position.y)];
flag = true;
}
}
if (sprite1.position.x<=720.0) {
if (flag) {
[sprite1 setPosition:ccp(sprite1.position.x-speed, self.position.y)];
[sprite2 setPosition:ccp(sprite1.position.x+480, self.position.y)];
}else {
[sprite2 setPosition:ccp(sprite2.position.x-speed, self.position.y)];
[sprite1 setPosition:ccp(sprite2.position.x+480, self.position.y)];
}
}
}
Interval : image