Skip to main content
Game Development

Return to Revisions

2 of 2
Summarised the general method in the first line. Formatted code.
Anko
  • 13.5k
  • 10
  • 56
  • 82

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

AltStyle によって変換されたページ (->オリジナル) /