StateStatus.java
package com.mygdx.game;
public class StateStatus {
public static int MAINMENU_STAGE = 1;
public static int GAME_STAGE = 2;
public static int STORE_STAGE = 3;
public static int flag = MAINMENU_STAGE;
}
GameStage.java
package com.mygdx.game;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
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.Image;
public class GameStage extends Stage {
Texture texture;
TextureRegion textureRegion;
Image bgImage;
Image newGameImage;
TextureRegion newGameTextureRegion;
public GameStage() {
super();
init();
}
public void init() {
texture = new Texture(Gdx.files.internal("data/game_stage.jpg"));
textureRegion = new TextureRegion(texture, 0, 48, 256, 208);
bgImage = new Image(textureRegion);
bgImage.setSize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
newGameTextureRegion = new TextureRegion(texture, 0, 0, 256, 48);
newGameImage = new Image(newGameTextureRegion);
newGameImage.setPosition((Gdx.graphics.getWidth()-256 * 2)/2, (Gdx.graphics.getHeight()-48)/2);
newGameImage.setSize(256 * 2, 48 *2);
this.addActor(bgImage);
this.addActor(newGameImage);
newGameImage.addListener(new InputListener(){
@Override
public boolean touchDown(InputEvent event, float x, float y,
int pointer, int button) {
StateStatus.flag = StateStatus.STORE_STAGE;
return true;
}
});
}
}
MainMenuStage.java
package com.mygdx.game;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
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.Image;
public class MainMenuStage extends Stage {
Texture texture;
TextureRegion textureRegion;
Image bgImage;
Image newGameImage;
TextureRegion newGameTextureRegion;
public MainMenuStage() {
super();
init();
}
public void init() {
texture = new Texture(Gdx.files.internal("data/mainmenu_stage.jpg"));
textureRegion = new TextureRegion(texture, 0, 48, 256, 208);
bgImage = new Image(textureRegion);
bgImage.setSize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
newGameTextureRegion = new TextureRegion(texture, 0, 0, 256, 48);
newGameImage = new Image(newGameTextureRegion);
newGameImage.setPosition((Gdx.graphics.getWidth()-256 * 2)/2, (Gdx.graphics.getHeight()-48)/2);
newGameImage.setSize(256 * 2, 48 *2);
this.addActor(bgImage);
this.addActor(newGameImage);
newGameImage.addListener(new InputListener(){
@Override
public boolean touchDown(InputEvent event, float x, float y,
int pointer, int button) {
StateStatus.flag = StateStatus.GAME_STAGE;
return true;
}
});
}
}
StoreStage.java
package com.mygdx.game;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
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.Image;
public class StoreStage extends Stage {
Texture texture;
TextureRegion textureRegion;
Image bgImage;
Image newGameImage;
TextureRegion newGameTextureRegion;
public StoreStage() {
super();
init();
}
public void init() {
texture = new Texture(Gdx.files.internal("data/store_stage.jpg"));
textureRegion = new TextureRegion(texture, 0, 48, 256, 208);
bgImage = new Image(textureRegion);
bgImage.setSize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
newGameTextureRegion = new TextureRegion(texture, 0, 0, 256, 48);
newGameImage = new Image(newGameTextureRegion);
newGameImage.setPosition((Gdx.graphics.getWidth()-256 * 2)/2, (Gdx.graphics.getHeight()-48)/2);
newGameImage.setSize(256 * 2, 48 *2);
this.addActor(bgImage);
this.addActor(newGameImage);
newGameImage.addListener(new InputListener(){
@Override
public boolean touchDown(InputEvent event, float x, float y,
int pointer, int button) {
StateStatus.flag = StateStatus.MAINMENU_STAGE;
return true;
}
});
}
}
MyGdxGame.java
package com.mygdx.game;
import com.badlogic.gdx.Application;
import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.InputProcessor;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Animation;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.ui.ImageButton;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable;
import com.badlogic.gdx.utils.Align;
import com.badlogic.gdx.utils.viewport.ScreenViewport;
public class MyGdxGame extends ApplicationAdapter {
GameStage gameStage;
MainMenuStage mainMenuStage;
StoreStage storeStage;
@Override
public void create() {
gameStage = new GameStage();
mainMenuStage = new MainMenuStage();
storeStage = new StoreStage();
}
public void stageUpdate(){
if(StateStatus.flag == StateStatus.MAINMENU_STAGE){
Gdx.input.setInputProcessor(mainMenuStage);
mainMenuStage.act();
mainMenuStage.draw();
}else if (StateStatus.flag == StateStatus.GAME_STAGE) {
Gdx.input.setInputProcessor(gameStage);
gameStage.act();
gameStage.draw();
}else if (StateStatus.flag == StateStatus.STORE_STAGE) {
Gdx.input.setInputProcessor(storeStage);
storeStage.act();
storeStage.draw();
}
}
@Override
public void dispose() {
}
@Override
public void render() {
Gdx.gl.glClearColor(1, 1, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
stageUpdate();
}
@Override
public void resize(int width, int height) {
}
}