package com.mygdx.game;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.audio.Music;
import com.badlogic.gdx.audio.Sound;
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;
TextureRegion newGameTextureRegion;
TextureRegion soundRegion;
TextureRegion musicRegion;
Image bgImage;
Image newGameImage;
Image soundImage;
Image musicImage;
Sound sound;
Music music;
public MainMenuStage() {
super();
Gdx.app.log("MyGdxGame", "MainMenuStage");
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);
soundRegion = new TextureRegion(texture, 0, 256, 256, 48);
soundImage = new Image(soundRegion);
soundImage.setPosition((Gdx.graphics.getWidth() - 256 * 2) / 2, (Gdx.graphics.getHeight() - 48) / 2 - 128);
soundImage.setSize(256 * 2, 48 * 2);
musicRegion = new TextureRegion(texture, 0, 304, 256, 48);
musicImage = new Image(musicRegion);
musicImage.setPosition((Gdx.graphics.getWidth() - 256 * 2) / 2, (Gdx.graphics.getHeight() - 48) / 2 - 256);
musicImage.setSize(256 * 2, 48 * 2);
this.addActor(bgImage);
this.addActor(newGameImage);
this.addActor(soundImage);
this.addActor(musicImage);
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;
}
});
soundImage.addListener(new InputListener() {
@Override
public boolean touchDown(InputEvent event, float x, float y,
int pointer, int button) {
sound.play();
return true;
}
});
musicImage.addListener(new InputListener() {
@Override
public boolean touchDown(InputEvent event, float x, float y,
int pointer, int button) {
if(!music.isPlaying())
music.play();
else
music.stop();
return true;
}
});
sound = Gdx.audio.newSound((Gdx.files.internal("data/chirp.wav")));
music = Gdx.audio.newMusic(Gdx.files.internal("data/bubblepop.ogg"));
music.setLooping(true);
}
@Override
public void dispose() {
super.dispose();
Gdx.app.log("MyGdxGame", "MainMenuStage dispose");
sound.dispose();
music.dispose();
}
}
