el.severo
el.severo

Reputation: 2277

parallax scrolling cocos2d

I've seen many tutorials but not similar with what I'm trying to build...

Creating a parallax view with 3 sprites (background, layer 1, layer 2)

//Adding a like this        
CCSprite *sprite = [CCSprite spriteWithFile:@"spriteImage.png"];
sprite.anchorPoint = CGPointZero;
[self addChild:sprite z:-1]; //and chaining the z's value for each sprite

How I implement the scroll of the screen and the sprites would move with different speed?

Any suggestions would be great!

P.S. Want to use touch events (when swiping to scroll)

Upvotes: 0

Views: 2412

Answers (2)

el.severo
el.severo

Reputation: 2277

Found it, you can add the sprite directly to a parallaxNode or add the sprite to a CCLayer and the CCLayer to parallaxNode; something like:

[parallaxNode addChild:sprite z:0 parallaxRatio:CGPointMake(0,0) positionOffset:ccp(x,y)];

Upvotes: 0

Chaosphere2112
Chaosphere2112

Reputation: 674

If you're using particularly large background images, you'll probably want to take a look at http://www.raywenderlich.com/1163/how-to-make-a-tile-based-game-with-cocos2d. Included in that tutorial is a guide to making images move when you scroll around.

Upvotes: 2

Related Questions