Java LIBGDX 创建主菜单
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16529869/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
LIBGDX creating a main menu
提问by James Young
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
所以我想为我的游戏创建一个主菜单,我被困在接下来要做什么 我已经完成了所有的艺术,它都是分层的,并打包在一个 .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.
如果有人能给我一些关于现在做什么的指导方针或教程,那就太好了,我已经看了很多地方,但他们没有给我所需的答案。
回答by Ben Poulson
Have a look at this tutorial which sums up what you want exactly:
看看这个教程,它总结了你想要的东西:
回答by sadaf2605
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.
基本上你需要1.创建一个皮肤,2.我们需要给它添加buttionTextureStyle。3.不要忘记添加字体,我花了一个小时才弄清楚默认情况下没有像buttonTextureStyle 4.的其他参数那样设置字体,然后创建一个带有已创建外观的按钮5.然后将该按钮添加到阶段。
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/
呼!我发现它很有帮助,也许它也可以帮助你:http: //www.sadafnoor.com/blog/how-to-create-simple-menu-in-libgdx/
回答by opmarq
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 .
我认为,如果您使用可以处理所有复杂性并帮助您使用少量代码创建漂亮 UI 的 Scene2D,那将会很容易。
you may need to check this link https://github.com/libgdx/libgdx/wiki/Scene2d.ui