Scrolling background stops after awhile? [closed]

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);
}

• Have you tried using your debugger to see what the values are when it's not scrolling and what path the code is taking? – doppelgreener Jun 26 '12 at 2:23
• What do u mean by "a while"? – XiaoChuan Yu Jun 26 '12 at 3:55
• The first background scrolls down, then the second image scrolls down, then I think it stops. Something is wrong in //reset. – Lewis Jun 26 '12 at 14:30

Looks like you you have duplicated the background position twice in the else part. I've inserted the 2 below

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);
}


Added: After the else statement you have background.position = .... in twice.

The first one needs to be background2.position

• Hi thanks for the reply, but I don't follow? – Lewis Jun 26 '12 at 18:36
• I've edited it so hopefully it more clearer – John Jun 26 '12 at 18:49