Java tutorial
package ac.uk.dmu.ash.game.screen; import ac.uk.dmu.ash.game.assets.AssetManager; import com.badlogic.gdx.Game; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.scenes.scene2d.InputEvent; import com.badlogic.gdx.scenes.scene2d.Stage; import com.badlogic.gdx.scenes.scene2d.ui.Label; import com.badlogic.gdx.scenes.scene2d.ui.Table; import com.badlogic.gdx.scenes.scene2d.ui.TextButton; import com.badlogic.gdx.scenes.scene2d.utils.Align; import com.badlogic.gdx.scenes.scene2d.utils.ClickListener; /** * The credits screen containing author and publisher information. * @author Michael */ public final class CreditsScreen extends GameScreen { /** * The credits. */ private final static String CREDITS = "Programming and story by Michael Bull.\n" + "All rights reserved.\n" + "\n" + "\n" + "Licensed code supplied by Graham Edgecombe\n" + "(files marked with @author Graham).\n" + "\n" + "\n" + "Gson libraries supplied by Google Inc covered by\n" + "the Apache license.\n" + "\n" + "\n" + "See the LICENSE file included with this release\n" + "for more details."; /** * The game assets. */ private final AssetManager assets; /** * The fps indicator label. */ private final Label fpsLabel; /** * The sprite batch. */ private final SpriteBatch spriteBatch = new SpriteBatch(); /** * The scene 2d stage. */ private final Stage stage = new Stage(); /** * Creates a new {@link CreditsScreen}. * @param game The game instance. * @param assets The game assets */ public CreditsScreen(final Game game, final AssetManager assets) { this.assets = assets; Gdx.input.setInputProcessor(stage); Table fpsTable = createTableWithLabel(assets, "ui_skin", Align.left, (Align.top | Align.left), "fps:"); fpsLabel = (Label) fpsTable.getCells().get(0).getWidget(); stage.addActor(fpsTable); Table creditsTable = createTableWithLabel(assets, "ui_skin", CREDITS); stage.addActor(creditsTable); TextButton backButton = createTextButton(assets, "ui_skin", "Back", new ClickListener() { @Override public void clicked(InputEvent event, float x, float y) { dispose(); game.setScreen(new MainMenuScreen(game, assets)); } }); Table buttonsTable = createTable(Align.left | Align.bottom); buttonsTable.add(backButton); stage.addActor(buttonsTable); } @Override public void render(float delta) { Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); fpsLabel.setText("fps: " + Gdx.graphics.getFramesPerSecond()); spriteBatch.begin(); drawTextureCentre(assets, spriteBatch, "background", 0, 0); spriteBatch.end(); stage.act(Gdx.graphics.getDeltaTime()); stage.draw(); // Table.drawDebug(stage); // adds coloured outline to cells within the tables that are in the stage } @Override public void dispose() { super.dispose(); spriteBatch.dispose(); stage.dispose(); } }