Back to project page diploma-assignment.
The source code is released under:
MIT License
If you think the Android project diploma-assignment listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.me.openingscreen; // w w w . j a v a 2 s .c o m import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.Batch; import com.badlogic.gdx.scenes.scene2d.Actor; import com.me.battlescreen.Constants; public class FloatingBackground extends Actor { private int backWidth; private Texture background; private float currX; private OpeningScreen screen; private boolean forth; private float OFFSET; public FloatingBackground(OpeningScreen s,Texture t) { background = t; screen=s; forth=true; } private void activateBitmap() { Constants.BACKWIDTH=backWidth; Constants.WIDTH_SCALE=background.getWidth()/ (float) (backWidth); Constants.HEIGHT_SCALE=background.getHeight()/ (float) (this.getHeight()); OFFSET=((float)backWidth)/(30*20); } private void calculateWidth(){ backWidth=(int) (this.getHeight()*((double)background.getWidth()/ background.getHeight())); this.setWidth(backWidth); } public void restart(){ currX=0; this.setX(0); calculateWidth(); activateBitmap(); } @Override public void draw(Batch batch,float parentAlpha){ if((forth && currX+screen.getWidth()>backWidth) || (!forth && currX<0)) forth=!forth; if(forth) currX+=OFFSET; else currX-=OFFSET; batch.draw(background,this.getX()-(int)currX,this.getY(),backWidth,this.getHeight()); } }