Scrolling background stops after awhile?

Posted by Lewis on Game Development See other posts from Game Development or by Lewis
Published on 2012-06-26T00:58:26Z Indexed on 2012/06/26 3:25 UTC
Read the original article Hit count: 323

Filed under:

Can anyone tell me where my maths is wrong please, it stops scrolling after awhile.

if (background.position.y < background2.position.y)
{
    background.position = ccp(background.contentSize.width / 2, background.position.y - 50 * delta);
    background2.position = ccp(background.contentSize.width / 2, background.position.y + background.contentSize.height);
}
else
{
    background.position = ccp(background2.contentSize.width / 2, background2.position.y - 50 * delta);
    background.position = ccp(background2.contentSize.width / 2, background2.position.y + background.contentSize.height);
}

//reset
if (background.position.y <-background.contentSize.height / 2)
{
    background.position = ccp(background.contentSize.width / 2 ,background2.position.y + background2.contentSize.height);
} 
else if (background2.position.y < -background2.contentSize.height / 2)
{
    background2.position = ccp(background2.contentSize.width / 2, background.position.y + background.contentSize.height);
}

© Game Development or respective owner

Related posts about parallaxscrolling