Android Open Source - Stickman Floating Text






From Project

Back to project page Stickman.

License

The source code is released under:

Apache License

If you think the Android project Stickman 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.wireframe.stickman;
/*from  w  w  w. ja v a  2s .  co  m*/
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.BitmapFont.TextBounds;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.math.Vector3;

public class FloatingText extends GameObject{
  public static final int LIFE_LENGTH = 2;
  private static FileHandle fontFNT;
  private static FileHandle fontPNG;

  private Color color;
  private BitmapFont font;
  private String message;
  private float speed = -1f;
  private float lifetime;
  
  

  public FloatingText(String message, float x, float y, Color color) {
    super(new Vector3(x,y,GameObject.Z_FLOATINGTEXTS), new Vector2(0,0));
    this.message = message;
    this.color = color;
    
    // Statically make the font
    if( fontFNT == null ){
      fontFNT = Gdx.files.internal("font.fnt");
      fontPNG = Gdx.files.internal("font.png");
    }
    
    // Font object
    font = new BitmapFont(fontFNT,fontPNG,true);
    
    // Assign width/height
    TextBounds bounds = font.getBounds(message);
    setSize(bounds.width, bounds.height);
  }

  public void update(){
    moveBy(0, speed);
    
    // LIFE
    lifetime += Gdx.graphics.getDeltaTime();
    if( lifetime > LIFE_LENGTH ){
      World.removeFloatingText(this);
    }
  }

  @Override
  public void draw(SpriteBatch batch) {
    int scaler = (int) (Math.min(LIFE_LENGTH, lifetime) / LIFE_LENGTH*255f);    
    font.setColor(color.r, color.g, color.b, scaler);
    font.draw(batch, message, getPosition().x, getPosition().y);
  }

  @Override
  public Rectangle getBounds() {
    return null;
  }
  
  public float getHeight(){
    return font.getXHeight();
  }

  public void setColor(Color color) {
    font.setColor(color);
  }

  @Override
  public void dispose() {
    font.dispose();
  }
}




Java Source Code List

com.wireframe.stickman.AICharacter.java
com.wireframe.stickman.AndroidGUI.java
com.wireframe.stickman.Brick.java
com.wireframe.stickman.Character.java
com.wireframe.stickman.Door.java
com.wireframe.stickman.Enemy.java
com.wireframe.stickman.FloatingText.java
com.wireframe.stickman.Friendly.java
com.wireframe.stickman.GUI.java
com.wireframe.stickman.GameObject.java
com.wireframe.stickman.GameRules.java
com.wireframe.stickman.Health.java
com.wireframe.stickman.Interactable.java
com.wireframe.stickman.Ladder.java
com.wireframe.stickman.Player.java
com.wireframe.stickman.Resources.java
com.wireframe.stickman.SmallButton.java
com.wireframe.stickman.Spawner.java
com.wireframe.stickman.Spikes.java
com.wireframe.stickman.StickmanGame.java
com.wireframe.stickman.StickmanResources.java
com.wireframe.stickman.Tile.java
com.wireframe.stickman.Toggleable.java
com.wireframe.stickman.WaterShore.java
com.wireframe.stickman.Water.java
com.wireframe.stickman.World.java
com.wireframe.stickman.android.AndroidLauncher.java
com.wireframe.stickman.desktop.DesktopLauncher.java
com.wireframe.stickman.desktop.EditorLauncher.java
com.wireframe.stickman.editor.MapMaker.java
com.wireframe.stickman.editor.MappingPanel.java
com.wireframe.stickman.editor.PlacedTile.java
com.wireframe.stickman.editor.SelectionPanel.java
com.wireframe.stickman.editor.SelectionTile.java
com.wireframe.stickman.editor.SizingPanel.java