Divide the position of each layer by the "distance" you want it to have from the camera.
For example: Create a couple of variables to represent the camera position, cameraX
and cameraY
. Set these to equal the position of your character, possibly adding on a bit extra in the direction of movement.
The main layer would just be positioned at
mainLayer.x = -cameraX;
the middle layer at something like
middleLayer.x = -cameraX * 0.5;
and the far layer at
farLayer.x = -cameraX * 0.2;
Change the constants as needed.
Iain
- 6.6k
- 3
- 35
- 46
default