Android Open Source - Castle-Invaders Simple Element






From Project

Back to project page Castle-Invaders.

License

The source code is released under:

GNU General Public License

If you think the Android project Castle-Invaders 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.noobygames.utils.ui;
/*from   w  ww. j av a2  s  .co  m*/

import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.math.Rectangle;

public class SimpleElement extends Element {
        
  /**marks the position and the size of the element**/
  private Rectangle position;
  /**the texture for the element**/
  private Texture tex;
  private TextureRegion texRegion;
  
  
  /**
   * @param position marks the position and the size
   * @param tex the texture **/
  public SimpleElement(Rectangle position, Texture tex){
    this.position = position;
    this.tex = tex;
    this.texRegion = null;
  }
  
  /**
   * @param position marks the position and the size
   * @param tex the texture **/
  public SimpleElement(Rectangle position){
    this.position = position;
    this.tex = null;
    this.texRegion = null;
  }
  
  /**
   * @param position marks the position and size
   * @param texRegion the texture region**/
  public SimpleElement(Rectangle position, TextureRegion texRegion){
    this.position = position;
    this.texRegion = texRegion;
    this.tex = null;
  }
  
  /**
   * @return the position
   */
  public Rectangle getPosition() {
    return position;
  }

  /**
   * @param position the position to set
   */
  public void setPosition(Rectangle position) {
    this.position = position;
  }
  
  /**
   * @param x x coordinate
   * @param y y coordinate
   * @param width the width
   * @param height the height
   * **/
  public void setPosition(float x, float y, float width, float height){
    this.position.set(x, y, width, height);
  }

  /**
   * @return the tex
   */
  public Texture getTex() {
    return tex;
  }

  /**
   * @param tex the tex to set
   */
  public void setTex(Texture tex) {
    this.tex = tex;
  }
  
  /**
   * @return the textureRegion
   */
  public TextureRegion getTexRegion() {
    return texRegion;
  }

  /**
   * @param texReg the textureRegion to set
   */
  public void setTexRegion(TextureRegion texReg) {
    this.texRegion = texReg;
  }
  
  /**Calls the batchers draw method
   * @param batch The SpriteBatcher**/
  public void drawIt(SpriteBatch batch){
    if(this.tex != null)
      this.draw(batch);
    else if(this.texRegion != null)
      this.drawTexRegion(batch);
  }
  
  /**Draws the element if it has a Texture**/
  private void draw(SpriteBatch batch){
    batch.draw(this.tex, this.position.x, this.position.y, this.position.width, this.position.height);
  }
  
  /**Draws the element if it has a TextureRegion**/
  private void drawTexRegion(SpriteBatch batch){
    batch.draw(this.texRegion, this.position.x, this.position.y, this.position.width, this.position.height);
  }

}




Java Source Code List

com.noobgygames.castleinvaders.ui.DragonUltiButton.java
com.noobgygames.castleinvaders.ui.ElementSwitcherButton.java
com.noobgygames.castleinvaders.ui.StoreElement.java
com.noobgygames.castleinvaders.ui.TextureElement.java
com.noobygames.castleinvaders.Assets.java
com.noobygames.castleinvaders.CastleInvaders.java
com.noobygames.castleinvaders.DynamicGameObject.java
com.noobygames.castleinvaders.GameLiving.java
com.noobygames.castleinvaders.GameObject.java
com.noobygames.castleinvaders.MainActivity.java
com.noobygames.castleinvaders.Main.java
com.noobygames.castleinvaders.Player.java
com.noobygames.castleinvaders.Projectile.java
com.noobygames.castleinvaders.Settings.java
com.noobygames.castleinvaders.WorldRenderer.java
com.noobygames.castleinvaders.World.java
com.noobygames.castleinvaders.mobs.Croco.java
com.noobygames.castleinvaders.mobs.EarthDragon.java
com.noobygames.castleinvaders.mobs.FireDragon.java
com.noobygames.castleinvaders.mobs.FireTroll.java
com.noobygames.castleinvaders.mobs.GameScreen.java
com.noobygames.castleinvaders.mobs.GreyTroll.java
com.noobygames.castleinvaders.mobs.IceDragon.java
com.noobygames.castleinvaders.mobs.IceTroll.java
com.noobygames.castleinvaders.mobs.Murloc.java
com.noobygames.castleinvaders.mobs.Orc.java
com.noobygames.castleinvaders.mobs.Skeleton.java
com.noobygames.castleinvaders.screens.GameScreen.java
com.noobygames.castleinvaders.screens.MainMenuScreen.java
com.noobygames.castleinvaders.screens.ScoreScreen.java
com.noobygames.castleinvaders.screens.SplashScreen.java
com.noobygames.castleinvaders.screens.StoreScreen.java
com.noobygames.castleinvaders.store.StoreObject.java
com.noobygames.castleinvaders.store.Store.java
com.noobygames.nerzal.castleinvaders.spells.Burning.java
com.noobygames.nerzal.castleinvaders.spells.Freeze.java
com.noobygames.nerzal.castleinvaders.spells.SpellEffect.java
com.noobygames.nerzal.castleinvaders.spells.Spells.java
com.noobygames.utils.ArrayListUtils.java
com.noobygames.utils.ObjectSelectionContainer.java
com.noobygames.utils.OverlapTester.java
com.noobygames.utils.exceptions.OutOfBoundingException.java
com.noobygames.utils.exceptions.SliderOutOfBoundingsException.java
com.noobygames.utils.ui.Button.java
com.noobygames.utils.ui.ClickableElement.java
com.noobygames.utils.ui.DropDownMenu.java
com.noobygames.utils.ui.Element.java
com.noobygames.utils.ui.RadioButton.java
com.noobygames.utils.ui.RadioGroupButton.java
com.noobygames.utils.ui.ScrollableElement.java
com.noobygames.utils.ui.SimpleElement.java
com.noobygames.utils.ui.Slider.java
com.noobygames.utils.ui.Table.java
com.noobygames.utils.ui.TextBox.java
com.noobygames.utils.ui.Text.java
com.noobygames.utils.ui.Window.java