Android Open Source - bbg-gdx-project-setup World Renderer






From Project

Back to project page bbg-gdx-project-setup.

License

The source code is released under:

MIT License

If you think the Android project bbg-gdx-project-setup 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.bluebananagames.gametemplate.render;
//from   w ww  .  j a v a  2  s  . com
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.bluebananagames.gametemplate.game.Player;
import com.bluebananagames.gametemplate.input.Control;
import com.bluebananagames.gametemplate.screen.GameScreen;

public class WorldRenderer {

  private GameScreen gameScreen;
  private SpriteBatch batch;

  private Sprite backgroundSprite;
  private BitmapFont font;

  public WorldRenderer(GameScreen gameScreen, SpriteBatch batch) {
    this.gameScreen = gameScreen;
    this.batch = batch;

    initializeFonts();
    initializeSprites();
  }

  public void dispose() {
  }

  private void initializeSprites() {
    backgroundSprite = gameScreen.getAssets().getSprite("background.jpg");
  }

  private void initializeFonts() {
    font = gameScreen.getAssets().getFont("font32.fnt");
  }

  public void render(float delta) {
    batch.begin();
    renderBackground();
    renderText();
    batch.end();
  }

  private void renderText() {
    Player player = gameScreen.getPlayers().first();

    String text = "...";
    if (player.getInputHandler().isControlPressed(Control.UP)) {
      text = "UP";
    }
    if (player.getInputHandler().isControlPressed(Control.DOWN)) {
      text = "DOWN";
    }
    if (player.getInputHandler().isControlPressed(Control.LEFT)) {
      text = "LEFT";
    }
    if (player.getInputHandler().isControlPressed(Control.RIGHT)) {
      text = "RIGHT";
    }
    if (player.getInputHandler().isControlPressed(Control.FIRE)) {
      text = "FIRE";
    }

    font.draw(batch, text, 100, 500);
  }

  private void renderBackground() {
    backgroundSprite.draw(batch);
  }

  // HELPERS

}




Java Source Code List

com.bluebananagames.gametemplate.Assets.java
com.bluebananagames.gametemplate.GameTemplateGame.java
com.bluebananagames.gametemplate.MainActivity.java
com.bluebananagames.gametemplate.Main.java
com.bluebananagames.gametemplate.game.PlayerColor.java
com.bluebananagames.gametemplate.game.Player.java
com.bluebananagames.gametemplate.input.Control.java
com.bluebananagames.gametemplate.input.ControllerInputHandler.java
com.bluebananagames.gametemplate.input.InputHandler.java
com.bluebananagames.gametemplate.input.InputMapping.java
com.bluebananagames.gametemplate.input.KeyboardInputHandler.java
com.bluebananagames.gametemplate.render.WorldRenderer.java
com.bluebananagames.gametemplate.screen.AbstractScreen.java
com.bluebananagames.gametemplate.screen.GameScreen.java