ImageButton für das Menü hinzugefügt(testing)

This commit is contained in:
Armin Benz 2017-04-14 21:09:16 +02:00
parent 99714c24ce
commit 25fe22da77
2 changed files with 36 additions and 2 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

View File

@ -6,16 +6,18 @@ import com.badlogic.gdx.audio.Music;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Gdx2DPixmap;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.Stage;
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.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable;
import de.samdev.colorrunner.CRGame;
import de.samdev.colorrunner.game.world.map.CRMapStorage;
@ -28,6 +30,7 @@ public class MainMenu implements Screen {
private Stage stage = new Stage();
private Table table = new Table();
private OrthographicCamera cam = new OrthographicCamera();
private Texture background = new Texture("images/background2.jpg");
@ -37,8 +40,35 @@ public class MainMenu implements Screen {
private TextButton buttonPlay1 = new TextButton("Play Level 1", skin);
private TextButton buttonPlay2 = new TextButton("Play Endless", skin);
private TextButton buttonExit = new TextButton("Exit", skin);
private TextButton buttonOption = new TextButton("Option", skin);
private TextButton buttonExit = new TextButton("Exit", skin);
private Texture myTexture = new Texture(Gdx.files.internal("menu/Settings.png"));
private TextureRegion myTextureRegion= new TextureRegion(myTexture);
private TextureRegionDrawable myTexRegionDrawable = new TextureRegionDrawable(myTextureRegion);
private ImageButton optionButton = new ImageButton(myTexRegionDrawable);
// folgendes mal als Beispiel :)
/*
button3.setSize(col_width*4,(float)(row_height*2));
button3.getStyle().imageUp = new TextureRegionDrawable(new TextureRegion(new Texture(Gdx.files.internal("switch_off.png"))));
button3.getStyle().imageDown = new TextureRegionDrawable(new TextureRegion(new Texture(Gdx.files.internal("switch_on.png"))));
button3.setPosition(col_width,Gdx.graphics.getHeight()-row_height*6);
button3.addListener(new InputListener(){
@Override
public void touchUp (InputEvent event, float x, float y, int pointer, int button) {
outputLabel.setText("Press a Button");
}
@Override
public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
outputLabel.setText("Pressed Image Button");
return true;
}
});
*/
private Label title = new Label("Color Runner", skin);
@ -48,6 +78,8 @@ public class MainMenu implements Screen {
music = CRGame.manager.get("sound/menusound.mp3", Music.class);
music.setLooping(true);
music.play();
}
@Override
@ -63,6 +95,7 @@ public class MainMenu implements Screen {
sb.draw(background, 0, 0);
sb.end();
stage.act();
stage.draw();
@ -115,6 +148,7 @@ public class MainMenu implements Screen {
table.setFillParent(true);
stage.addActor(table);
stage.addActor(optionButton);
Gdx.input.setInputProcessor(stage);
}