Back to project page bbg-gdx-project-setup.
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.
package com.bluebananagames.gametemplate.screen; // www .j a v a 2 s .co m import java.util.Arrays; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import com.badlogic.gdx.audio.Music; import com.badlogic.gdx.audio.Sound; import com.badlogic.gdx.controllers.Controller; import com.badlogic.gdx.controllers.Controllers; import com.badlogic.gdx.controllers.mappings.Ouya; import com.badlogic.gdx.graphics.glutils.ShapeRenderer; import com.badlogic.gdx.utils.Array; import com.bluebananagames.gametemplate.GameTemplateGame; import com.bluebananagames.gametemplate.game.Player; import com.bluebananagames.gametemplate.game.PlayerColor; import com.bluebananagames.gametemplate.input.Control; import com.bluebananagames.gametemplate.input.ControllerInputHandler; import com.bluebananagames.gametemplate.input.InputMapping; import com.bluebananagames.gametemplate.input.KeyboardInputHandler; import com.bluebananagames.gametemplate.render.WorldRenderer; public class GameScreen extends AbstractScreen { private static final boolean DEBUG = false; private static final ScheduledExecutorService scheduler = Executors .newSingleThreadScheduledExecutor(); WorldRenderer worldRenderer; private Array<Player> players = new Array<Player>(); private ShapeRenderer debugRenderer = new ShapeRenderer(); private Sound sfx; private Music music; public GameScreen(GameTemplateGame game) { super(game); assets.preloadSprites(Arrays.asList("background.jpg")); assets.preloadFonts(Arrays.asList("font32.fnt")); assets.preloadSFXs(Arrays.asList("sfx.wav")); assets.preloadMusic(Arrays.asList("music.mp3")); // TODO: preload other assets for this screen worldRenderer = new WorldRenderer(this, batch); sfx = assets.getSound("sfx.wav"); music = assets.getMusic("music.mp3"); music.play(); initializePlayers(); } private void initializePlayers() { Player player = new Player(); player.setColor(PlayerColor.BLUE); Array<Controller> controllers = Controllers.getControllers(); if (Ouya.runningOnOuya) { ControllerInputHandler inputHandler = new ControllerInputHandler(); inputHandler.setController(controllers.get(0)); inputHandler.setMapping(InputMapping.OUYAMapping()); player.setInputHandler(inputHandler); } else { if (Controllers.getControllers().size > 0) { ControllerInputHandler controllerInputHandler = new ControllerInputHandler(); controllerInputHandler.setController(Controllers .getControllers().first()); controllerInputHandler .setMapping(InputMapping.XBOX360Mapping()); player.setInputHandler(controllerInputHandler); } else { KeyboardInputHandler keyboardInputHandler = new KeyboardInputHandler(); keyboardInputHandler.setMapping(InputMapping .KeyboardArrowsMapping()); player.setInputHandler(keyboardInputHandler); } } players.add(player); } @Override public void show() { } @Override public void hide() { // TODO Auto-generated method stub } @Override public void pause() { // TODO Auto-generated method stub } @Override public void resume() { // TODO Auto-generated method stub } @Override public void render(float delta) { super.render(delta); batch.setProjectionMatrix(camera.combined); debugRenderer.setProjectionMatrix(camera.combined); worldRenderer.render(delta); if (players.get(0).getInputHandler().isControlPressed(Control.FIRE)) { sfx.play(); } } public Array<Player> getPlayers() { return players; } }