In my game, the player never moves, but rather the world around it does.
I can't figure out how to do this with CCParallaxNode, because every example I can find is touch-based.
Is there any way to do this?
Automatic parallax
(3 posts) (3 voices)-
Posted 1 year ago #
-
I'm a newbie but here's what i did to get CCParallaxNode to work:
CCParallaxNode *voidNode = [CCParallaxNode node];
CCSprite *city = [CCSprite spriteWithFile:@"city.png" rect:CGRectMake(0, 0, 4096, 256)];
city.anchorPoint = ccp(0,0);
[voidNode addChild:city z:1 parallaxRatio:ccp(0.2f,0.0f) positionOffset:ccp(-20,64)];CCSprite *buildings = [CCSprite spriteWithFile:@"buildings.png" rect:CGRectMake(0, 0,16384, 256) ];
buildings.anchorPoint = ccp(0,0);
[voidNode addChild:buildings z:2 parallaxRatio:ccp(0.6f,0.0f) positionOffset:ccp(-20,64)];...
I add my player CCSprite to the same parent of the CCParallaxNode and animate him walking.
...Then to create the parallax effect I create a CCMoveBy action:
id go = [CCMoveBy actionWithDuration:5 position:ccp(-1000,0)];
id seq = [CCSequence actions:go, nil];
[voidNode runAction: [CCRepeatForever actionWithAction:seq ] ];I hope this helps :-)
Posted 1 year ago # -
The Parallax test (included in the Cocos2D distribution) does both touch movement and auto-movement. @bone is right - just run the action of your choice on the parallax node. You want to move the backround parallax node in the opposite direction from which your player is walking. You don't need to add your player to the parallax node. Just add the player sprite to a z order above the parallax node in the center of your screen. When the background moves to the left, face your player to the right and when the background moves to the right, face your player to the left, etc... When the bacround is moving, you can do an animation on your player to make it look like it is walking....does any of this make sense?
Dave
Posted 1 year ago #
Reply
You must log in to post.