Java-主菜单的LIBGDX背景显示为白色
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了Java-主菜单的LIBGDX背景显示为白色,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含5223字,纯文字阅读大概需要8分钟。
内容图文
![Java-主菜单的LIBGDX背景显示为白色](/upload/InfoBanner/zyjiaocheng/658/ccb9734765a740d3b64be20f06485e7e.jpg)
我的背景图片没有显示,它像这样在角落显示为白色正方形.
https://dl.dropboxusercontent.com/u/45938379/menu.png
我需要知道如何解决这个问题,正如您所看到的那样,我的演员正在展示它的背后.
这是我的代码
public class MainMenu implements Screen {
CrazyZombies game;
Stage stage;
TextureAtlas atlas;
Skin skin;
SpriteBatch batch;
Button play, option, quit, custom, store;
TextureRegion backGround;
public MainMenu(CrazyZombies game) {
this.game = game;
}
@Override
public void render(float delta) {
Gdx.gl.glClearColor(0.09f, 0.28f, 0.2f, 1);
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
stage.act(delta);
batch.begin();
stage.draw();
drawBackGround();
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);
/**
* quit Button
*/
TextButtonStyle styleQuit = new TextButtonStyle();
styleQuit.up = skin.getDrawable("8layer");
styleQuit.down = skin.getDrawable("8layer");
quit = new Button(styleQuit);
quit.setWidth(854);
quit.setHeight(480);
quit.setX(Gdx.graphics.getWidth() / 2 - quit.getWidth() / 2);
quit.setY(Gdx.graphics.getHeight() / 2 - quit.getHeight() / 2);
quit.addListener(new InputListener() {
public boolean touchDown(InputEvent event, float x, float y,
int pointer, int button) {
return true;
}
public void touchUp(InputEvent event, float x, float y,
int pointer, int button) {
}
});
/**
* End quit Button
*/
/**
* store Button
*/
TextButtonStyle styleStore = new TextButtonStyle();
styleStore.up = skin.getDrawable("9layer");
styleStore.down = skin.getDrawable("9layer");
store = new Button(styleStore);
store.setWidth(854);
store.setHeight(480);
store.setX(Gdx.graphics.getWidth() / 2 - store.getWidth() / 2);
store.setY(Gdx.graphics.getHeight() / 2 - store.getHeight() / 2);
store.addListener(new InputListener() {
public boolean touchDown(InputEvent event, float x, float y,
int pointer, int button) {
return true;
}
public void touchUp(InputEvent event, float x, float y,
int pointer, int button) {
game.setScreen(new StoreScreen(game));
}
});
/**
* End store Button
*/
/**
* customs Button
*/
TextButtonStyle styleCustom = new TextButtonStyle();
styleCustom.up = skin.getDrawable("10layer");
styleCustom.down = skin.getDrawable("10layer");
custom = new Button(styleCustom);
custom.setWidth(854);
custom.setHeight(480);
custom.setX(Gdx.graphics.getWidth() / 2 - custom.getWidth() / 2);
custom.setY(Gdx.graphics.getHeight() / 2 - custom.getHeight() / 2);
custom.addListener(new InputListener() {
public boolean touchDown(InputEvent event, float x, float y,
int pointer, int button) {
return true;
}
public void touchUp(InputEvent event, float x, float y,
int pointer, int button) {
game.setScreen(new CustomScreen(game));
}
});
/**
* End customs Button
*/
/**
* Options Button
*/
TextButtonStyle styleOptions = new TextButtonStyle();
styleOptions.up = skin.getDrawable("11layer");
styleOptions.down = skin.getDrawable("11layer");
option = new Button(styleOptions);
option.setWidth(854);
option.setHeight(480);
custom.setX(Gdx.graphics.getWidth() / 2 - custom.getWidth() / 2);
custom.setY(Gdx.graphics.getHeight() / 2 - custom.getHeight() / 2);
option.addListener(new InputListener() {
public boolean touchDown(InputEvent event, float x, float y,
int pointer, int button) {
return true;
}
public void touchUp(InputEvent event, float x, float y,
int pointer, int button) {
game.setScreen(new OptionScreen(game));
}
});
/**
* End Options Button
*/
/**
* Play Button
*/
TextButtonStyle stylePlay = new TextButtonStyle();
stylePlay.up = skin.getDrawable("7layer");
stylePlay.down = skin.getDrawable("7layer");
play = new Button(stylePlay);
play.setWidth(854);
play.setHeight(480);
play.setX(Gdx.graphics.getWidth() / 2 - play.getWidth() / 2);
play.setY(Gdx.graphics.getHeight() / 2 - play.getHeight() / 2);
play.addListener(new InputListener() {
public boolean touchDown(InputEvent event, float x, float y,
int pointer, int button) {
return true;
}
public void touchUp(InputEvent event, float x, float y,
int pointer, int button) {
game.setScreen(new GameScreen(game));
}
});
/**
* End Play Button
*/
stage.addActor(play);
stage.addActor(option);
stage.addActor(store);
stage.addActor(custom);
stage.addActor(quit);
}
@Override
public void show() {
Audio.playMusic(true);
batch = new SpriteBatch();
atlas = new TextureAtlas("data/mainmenu/mainmenu.pack");
skin = new Skin();
skin.addRegions(atlas);
backGround = atlas.findRegion("background");
backGround.getRegionHeight();
backGround.getRegionWidth();
}
public void drawBackGround() {
float w = 854;
float h = 480;
float y = 0;
float x = 0;
batch.draw(backGround, x, y, w, h);
}
@Override
public void hide() {
dispose();
}
@Override
public void pause() {
}
@Override
public void resume() {
}
@Override
public void dispose() {
batch.dispose();
skin.dispose();
atlas.dispose();
stage.dispose();
}
}
我也注意到的是,如果我摆脱了
stage.draw();
图像出现.
解决方法:
从batch.begin()和batch.end()中取出stage.draw().舞台上确实有它自己的Spritebatch,所以您目前确实有一些同伴.我认为确实会造成麻烦.所以最好的方法是这样的:
@Override
public void render(float delta) {
Gdx.gl.glClearColor(0.09f, 0.28f, 0.2f, 1);
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
stage.act(delta);
stage.draw();
batch.begin();
drawBackGround();
batch.end();
}
我建议您将背景放到舞台上.图像也是一个Actor,因此您可以将其添加到舞台中,然后调用.toBack()(Back)将其置于背景中.
Libgdx Image
内容总结
以上是互联网集市为您收集整理的Java-主菜单的LIBGDX背景显示为白色全部内容,希望文章能够帮你解决Java-主菜单的LIBGDX背景显示为白色所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。