Suppose I have three layers: a foreground, an intermediate-ground and a background. What is involved in using these three layers to create parallax scrolling?
Answer
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.
No comments:
Post a Comment