简体   繁体   English

LIBGDX为主菜单创建演员和舞台

[英]LIBGDX creating actors and stage for the main menu

I need to know how i would go about setting up a stage and adding actors to it for my main menu. 我需要知道如何设置一个舞台并为我的主菜单添加演员。

Here is my code so far 到目前为止,这是我的代码

public class MainMenu implements Screen {

CrazyZombies game;
Stage stage;
TextureAtlas atlas;
SpriteBatch batch;
Skin skin;
Button button;

TextureRegion firstLayer, secondLayer, thirdLayer, fourthLayer,
    fifthLayer, sixthLayer, seventhLayer, eighthLayer, ninthLayer,
    tenthLayer, eleventhLayer;

Sprite road, backTrees, sideTrees, bottemTrees, light, poles,
    play, quit, store, custom, options;

public MainMenu(CrazyZombies game){
    this.game = game;
}

@Override
public void render(float delta) {
    Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
    Gdx.gl.glClearColor(0.09f, 0.28f, 0.2f, 1);

    batch.begin();
    road.draw(batch);
    backTrees.draw(batch);
    sideTrees.draw(batch);
    bottemTrees.draw(batch);
    light.draw(batch);
    poles.draw(batch);
    play.draw(batch);
    quit.draw(batch);
    store.draw(batch);
    custom.draw(batch);
    options.draw(batch);
    batch.end();

}

@Override
public void resize(int width, int height) {    
    Gdx.input.setInputProcessor(stage);

}

@Override
public void show() {
    Audio.playMusic(true);

    batch = new SpriteBatch();      
    atlas = new TextureAtlas("data/mainmenu/MainMenu.pack");

    firstLayer = atlas.findRegion("1layer");
    secondLayer = atlas.findRegion("2layer");
    thirdLayer = atlas.findRegion("3layer");
    fourthLayer = atlas.findRegion("4layer");
    fifthLayer = atlas.findRegion("5layer");
    sixthLayer = atlas.findRegion("6layer");
    seventhLayer = atlas.findRegion("7layer");
    eighthLayer = atlas.findRegion("8layer");
    ninthLayer = atlas.findRegion("9layer");
    tenthLayer = atlas.findRegion("10layer");
    eleventhLayer = atlas.findRegion("11layer");


    road = new Sprite(firstLayer);
    backTrees = new Sprite(secondLayer);
    sideTrees = new Sprite(thirdLayer);
    bottemTrees = new Sprite(fourthLayer);
    light = new Sprite(fifthLayer);
    poles = new Sprite(sixthLayer);
    play = new Sprite(seventhLayer);
    quit = new Sprite(eighthLayer);
    store = new Sprite(ninthLayer);
    custom = new Sprite(tenthLayer);
    options = new Sprite(eleventhLayer);

}

@Override
public void hide() {
    dispose();
}

@Override
public void pause() {

}

@Override
public void resume() {
}

@Override
public void dispose() {
    batch.dispose();
    atlas.dispose();
    Audio.dispose();
}

} }

The bits that i need to become actors are: - play - quit - store - custom - options 我需要成为演员的位是: - play - quit - store - custom - options

All my code does at the moment is just display my main menu i need to get the stage and actors setup in order to get the buttons working. 我的所有代码目前只是显示我的主菜单,我需要让舞台和演员设置,以使按钮工作。

Take a look at TableLayout and also take a look at TextButton or maybe Button . 看一下TableLayout ,看看TextButton或者Button


Here is a good tutorial . 这是一个很好的教程 Work through it and you will understand how to work with the Screen2D and how to create a simple menu. 通过它,您将了解如何使用Screen2D以及如何创建一个简单的菜单。 -> Direkt link to Menucreation of the Blog - > Direkt链接到Blog的Menucreation

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM