Android Open Source - diploma-assignment Floating Background






From Project

Back to project page diploma-assignment.

License

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.

Java Source Code

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());
  }
}




Java Source Code List

com.me.battlescreen.BallistaArrow.java
com.me.battlescreen.Ballista.java
com.me.battlescreen.BattlePlayer.java
com.me.battlescreen.BattleScreen.java
com.me.battlescreen.Bot.java
com.me.battlescreen.Castle.java
com.me.battlescreen.CleanBackground.java
com.me.battlescreen.ComputerPlayer.java
com.me.battlescreen.Constants.java
com.me.battlescreen.HumanPlayer.java
com.me.battlescreen.Monster.java
com.me.battlescreen.MyButton.java
com.me.battlescreen.MyLabel.java
com.me.battlescreen.OpponentMonster.java
com.me.battlescreen.PlayerMonster.java
com.me.battlescreen.TimeLabel.java
com.me.battlescreen.UnitButton.java
com.me.battlescreen.getTextures.java
com.me.battlescreen.iAttacking.java
com.me.battlescreen.iHittable.java
com.me.battlescreen.iUpdateable.java
com.me.main.MyGame.java
com.me.main.Player.java
com.me.mygdxgame.MainActivity.java
com.me.openingscreen.AbstractMenu.java
com.me.openingscreen.Constants.java
com.me.openingscreen.FirstMenu.java
com.me.openingscreen.FloatingBackground.java
com.me.openingscreen.OpeningScreen.java
com.me.openingscreen.PlayerMenu.java
com.me.openingscreen.ResetMenu.java
com.me.openingscreen.StatisticsMenu.java
com.me.openingscreen.UpgradeButton.java
com.me.openingscreen.UpgradeMenu.java