Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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);
}
share|improve this question

closed as too localized by doppelgreener, Byte56, Josh Petrie, Laurent Couvidou, Trevor Powell Dec 6 '12 at 5:29

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

    
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

1 Answer 1

up vote 3 down vote accepted

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

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.