0

I want to move a background picture continuously from left to right. I got a refrence from infinite-background picture

but in this the background image is moving right to left but i want from left to right. i tried to make changes in the above code, but this is not working for me.. can anyone please tell me how to do this?

Community
  • 1
  • 1
KsK
  • 675
  • 1
  • 10
  • 22

1 Answers1

3

You should be able to just change - to + for x and reverse the if conditions...

Try this:

-(void)scrollBackground:(ccTime)dt
{
    CGSize s = [[CCDirector sharedDirector] winSize];

    CGPoint pos1 = mBG1.position;
    CGPoint pos2 = mBG2.position;

    pos1.x += MM_BG_SPEED_DUR;
    pos2.x += MM_BG_SPEED_DUR;


    if(pos1.x >= (s.width*0.5f) )
    {
        pos1.x = pos2.x - s.width;
    }

    if(pos2.x >= (s.width*0.5f) )
    {
        pos2.x = pos1.x - s.width;
    }

    mBG1.position = pos1;
    mBG2.position = pos2;

}
Dustin
  • 94
  • 1
  • 3
  • thnaks.. previously i was trying -(pos2.x + s.width;) thats y it was not working.. but with ur answer its working now – KsK Apr 30 '13 at 06:39
  • It works, but you are changing when edge of the texture is on center of the screen. Good to change when it is on corner. -:) – Guru Apr 30 '13 at 06:42
  • Yeah, true @Guru. Should be able to just remove the `*0.5f` in the if statement for that... – Dustin Apr 30 '13 at 06:55