ikarma khan
ikarma khan

Reputation: 83

how to move background images continously cocos2d

I am fairly new to cocos2D and i am experiencing a problem that made me stuck on my game development. I have to background images, one is an image of a road and the other one is of footpath, what i want is to move the road image faster than the footpath image? How can i accomplish this task? Please help. Thanking you in anticipation.

Upvotes: 1

Views: 1148

Answers (2)

Savlon
Savlon

Reputation: 789

id roadMovementAction = [CCMoveBy actionWithDuration 0.5f position: ccp(-32,0)];

id footPathMovementAction = [CCMoveBy actionWithDuration 1.0f position: ccp(-32,0)];

[roadImage runAction: roadMovementAction];

[footPathImage runAction: footPathMovementAction];

Basically you're just moving the background images -32 pixels on the x axis... quite simple :)

you also might want to chuck in an if statement so when the images leave the screen it replaces them and repeats or whatever it is you're trying to do :)

hope that helped

Upvotes: 0

James Webster
James Webster

Reputation: 32066

Have a look at CCParallaxNode. It's part of cocos2d.

Upvotes: 2

Related Questions