LIBGDX creating a main menu

北城余情 提交于 2021-02-06 09:31:30

问题


So i want to create a mainmenu for my game and i'm stuck on what to do next i have all the art done and it's all in layers and packed in a .pack

public class MainMenu implements Screen {

CrazyZombies game;
Stage stage;
BitmapFont font;
TextureAtlas MainMenu;
Texture road;
Skin skin;
SpriteBatch batch;

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);

    stage.act(delta);

    batch.begin();
    stage.draw();
    batch.end();
}

@Override
public void resize(int width, int height) {
    if(stage == null)
        stage = new Stage(width, height, true);
    stage.clear();

    Gdx.input.setInputProcessor(stage);

}

@Override
public void show() {
    batch = new SpriteBatch();
    skin = new Skin();
    MainMenu = new TextureAtlas("data/mainmenu/MainMenu.pack");

}

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

@Override
public void pause() {

}

@Override
public void resume() {

}

@Override
public void dispose() {
    batch.dispose();
    skin.dispose();
    MainMenu.dispose();
    stage.dispose();
}
}

If anyone could give me some guidelines or tutorials on what to do now it would be great i've looked in a lot of places but they have not given me the required answers.


回答1:


Have a look at this tutorial which sums up what you want exactly:

LibGDX: Using a Splash Screen or Menu




回答2:


Basically you need to 1. create a skin, and 2. we need to add buttionTextureStyle to it. 3. Don't forget to add fonts, it took me a hour to figure out that fonts are not set by default like other parameters of buttonTextureStyle 4. and then you create a button with created skin 5. and then add that button to the stage.

Phew! I have found it helpful, Maybe it can help you as well: http://www.sadafnoor.com/blog/how-to-create-simple-menu-in-libgdx/




回答3:


i think it will be easy if u use scene2D that will handle all the complexity and help you to create a nice looking UI with a little bit of code .

you may need to check this link https://github.com/libgdx/libgdx/wiki/Scene2d.ui



来源:https://stackoverflow.com/questions/16529869/libgdx-creating-a-main-menu

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!