views:

491

answers:

2

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

A: 

It's not clear what you are trying to accomplish here. Can you elaborate?

David Whatley
+1  A: 

If the gap is just one pixel, it's likely this is just the way OpenGL/Cocos2D behaves.

Instead of making your images 480x320, make them 482x320, and make them overlap with those extra pixels. Then the gap will be gone.

nash