Java tutorial
/******************************************************************************* * Copyright (c) HALive, 2015. * For Licence information see LICENSE.md ******************************************************************************/ package halive.shootinoutside.menu; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.ScreenAdapter; import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.scenes.scene2d.Stage; import com.badlogic.gdx.scenes.scene2d.ui.Label; import com.badlogic.gdx.scenes.scene2d.ui.ProgressBar; import com.badlogic.gdx.scenes.scene2d.ui.Skin; import com.badlogic.gdx.scenes.scene2d.ui.Table; import com.badlogic.gdx.utils.viewport.FitViewport; import halive.shootinoutside.misc.UIConstants; public class LoadingScreen extends ScreenAdapter { private Skin skin; private Stage stage; private MainMenu menu; private Label statusLabel; private ProgressBar progressBar; private boolean pchanged = false; private float progress; private boolean schanged = false; private String status; public LoadingScreen(MainMenu menu) { this.menu = menu; } private void init() { float h = Gdx.graphics.getHeight(); float w = Gdx.graphics.getWidth(); stage = new Stage(new FitViewport(w, h)); skin = UIConstants.Menues.loadSkin(); Table table = new Table(skin); statusLabel = new Label("Loading...", skin); table.add(statusLabel).padBottom(UIConstants.Menues.PADDING_BOTTOM).row(); progressBar = new ProgressBar(0.0f, 100.0f, 0.1f, false, skin, "default"); table.add(progressBar).size(500, 80).row(); table.setFillParent(true); stage.addActor(table); } public void updateStatus(String msg) { schanged = true; status = msg; } public void updateProgressBar(float f) { pchanged = true; progress = f; } public MainMenu getMenu() { return menu; } @Override public void show() { init(); } @Override public void resize(int width, int height) { stage.getViewport().update(width, height, false); } @Override public void render(float delta) { Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); if (pchanged) { pchanged = false; progressBar.setValue(progress); } if (schanged) { schanged = false; statusLabel.setText(status); } stage.act(delta); stage.draw(); } @Override public void dispose() { stage.dispose(); skin.dispose(); } }