This morning I implemented a simple parallax system that creates the illusion of depth by using gravity data from the accelerometer with Corona SDK

First, I start to poll the accelerometer 100 times per second.

system.setAccelerometerInterval( 100 ) -- 100 hz is max

Gravity data from the accelerometer is then used to offset the angle of view. Illusion of depth is created by slightly moving the layers in the right direction, the magnitude of the movement depending on the distance to the eye.

To manage the scene I created 10 different layers. I placed the smaller shark in the front layer (layer 0), the larger shark in the middle (layer 5) and the back image to the background (layer 10).

Continue reading