Our amazing art team has provided all our level assets cut up into depth layers. to allow for our parallax effect.
This allows us to move each area of the background separately at different speeds. By moving the further pieces slowly we create the illusion of depth. This effect is called parallax.
When we run the game we slide all the pieces along at different speeds with a second copy following behind for a seamless effect.
To manage this in code, the information for each Layer is stored in a custom class.
This code contains a record of which image should be used for this layer, how fast this layer should move in relation to the games speed, a record of whether or not the layer is currently in use and a setting for type (some layers will be particle effects and require some different code to alter).
The information for each layer is stored in an array in the Area class which holds the information for each area as a whole.
This includes the information of the start and end transitions for areas that need them. The transition images sit on top of all the other images to hide the seems
Add caption |
Once the Area and Layer classes are in place the rest is fairly simple.
Storing the various Areas looks like this.
The Current Area is stored as an integer (to access a part of the above array) and the parallax system moves each piece forward like so
end code