Coding a parallax background

Much of the code that makes the backgrounds work is the same as it was in the scrolling shooter project. However, we will be coding a background-specific transform that extends Transform and we will also be using the Camera class to tweak the position of the backgrounds and make them create a parallax effect as well as vertical movement(compared to just horizontal in the previous project).

We will see the tricks and the code required to achieve a parallax scrolling background effect. The parallax effect is when different layers of backgrounds are moved at different speeds to achieve the effect of motion and depth. By moving the front layer(s) faster than the back the distance/depth effect is achieved.

To be clear, the ...

Get Learning Java by Building Android Games - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.