Java tutorial
/******************************************************************************* * Copyright (c) HALive, 2015. * For Licence information see LICENSE.md ******************************************************************************/ package halive.shootinoutside.mapeditor; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.ScreenAdapter; import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.OrthographicCamera; import com.badlogic.gdx.scenes.scene2d.InputEvent; import com.badlogic.gdx.scenes.scene2d.InputListener; import com.badlogic.gdx.scenes.scene2d.Stage; import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane; import com.badlogic.gdx.scenes.scene2d.ui.Skin; import com.badlogic.gdx.scenes.scene2d.ui.Table; import com.badlogic.gdx.utils.viewport.ScreenViewport; import halive.shootinoutside.common.core.game.map.GameMap; import halive.shootinoutside.game.input.GameControls; import halive.shootinoutside.game.map.GameMapRenderer; import halive.shootinoutside.mapeditor.menu.MapEditorGameOptionMenu; import halive.shootinoutside.menu.MainMenu; import halive.shootinoutside.misc.UIConstants; import java.util.Map; public class MapEditor extends ScreenAdapter { private GameMap map; private Stage stage; private MapEditorGameOptionMenu optionMenu; private MainMenu menu; private MapEditorHUD hud; private MapRenderingActor mapRenderer; private Table table; private Skin skin = UIConstants.Menues.loadSkin(); public MapEditor(GameMap map, MainMenu menu) { this.map = map; stage = new Stage(); this.menu = menu; this.hud = new MapEditorHUD(this); this.mapRenderer = new MapRenderingActor(this); } @Override public void show() { Gdx.input.setInputProcessor(stage); Gdx.graphics.setContinuousRendering(true); this.optionMenu = new MapEditorGameOptionMenu(new ScreenViewport(), this); optionMenu.init(); stage.addListener(new InputListener() { @Override public boolean keyDown(InputEvent event, int keycode) { if (GameControls.OPTION_MENU.isValidKeycode(keycode)) { optionMenu.toggleMenu(); System.out.println("Toggle option Menu"); return true; } return mapRenderer.keyDownToggled(event, keycode); } @Override public boolean keyUp(InputEvent event, int keycode) { return mapRenderer.keyUpToggled(event, keycode); } }); table = new Table(skin); table.add(new ScrollPane(mapRenderer, skin)).center().width(800).height(600).row(); stage.addActor(table); } @Override public void render(float delta) { Gdx.gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f); Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); if (!optionMenu.isMenuActive()) stage.draw(); stage.act(delta); optionMenu.render(delta); } @Override public void resize(int w, int h) { mapRenderer.resize(w, h); } public GameMap getMap() { return map; } public Stage getStage() { return stage; } }