The Parallax Class
It's pretty simple to use the Parallax, first we shall create an object from its class.
Parallax p = new Parallax();After that, the “backgrounds” will be added.
p.add(“fundo4.png”); p.add(“fundo3.png”); p.add(“fundo2.png”); p.add(“fundo.png”);Note: The first "backgrounds" to be inserted will be the last layers of the plan.
1 - Adjusting Speed
There are three methods in this class in charge of adjusting the speed of the plans: setVelAllLayers, setVelAllLayersStandard e setVelLayer.
setVelAllLayers(double velMainLayerX, double velMainLayerY) // Adjusts the speed of all layers from the main layer. // It divides the speed of the following layers by 2. setVelAllLayersStandard() // Adjusts the speed of all layers from the main layer setVelLayer(double velX, double velY,ParallaxLayers bg) // Assigns velX and VelY to the layer passed as parameter
2 - Other methods
drawLayers() //Draw all the layers. repeatLayers(int windowWidth,int windowHeigth, boolean axisX) // Makes the whole layer return to its initial position as soon as it reached its final position. If Boolean // axisX is true, the layers from the X axis are repeated, otherwise, the layers from the Y axis are repeated. moveLayersStandardX(boolean left) // moves all the layers to the left if true, otherwise moves them to the right. moveLayersStandardY(boolean up) // move all the layers up to the true case, otherwise moves them down. setMainLayer(ParallaxLayers layer) // sets the main layer getMainLayer() // returns the main layer setVelMainLayer(double x,double y) // assings the speed the main layer, velX and velY. setVelLayerX(double velX,ParallaxLayers bg ) // sets the speed of the layer in the X axis setVelLayerY(double velY,ParallaxLayers bg ) // sets the speed of the layer in the Y axis public void setVelAllLayers() // Assigns the value of the speed for all the layers. // Note: If you use this method, the method setVelMainLayer (double x, double y) must be called before, // otherwise all the layers will have 0 as value.
UFF - Universidade Federal Fluminense - Institudo de Computação - Ciência da Computação