Creating a parallax effect
Cocos2d-x has a special node called ParallaxNode
, and one surprising thing about it is how little you get to use it! ParallaxNode
helps create a parallax effect with finite layers, or finite scrolling, which means that you can use it if your game screen has a limit to how much it can scroll each way. Implementing ParallaxNode
to a game screen that can scroll indefinitely, such as the one in Victorian Rush Hour, usually requires more effort than it takes to build your own effect.
A parallax effect is created by moving objects at different depths at different speeds. The farther a layer appears from the screen, the slower its speed should be. In a game, this usually means that the player sprite's speed is fractioned to all the layers that appear behind it, and multiplied for the layers that appear in front of the player sprite:
Let's add this to our game.