我的背景图片没有显示,它像这样在角落显示为白色正方形.
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;}@OverrIDepublic 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();}@OverrIDepublic 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);}@OverrIDepublic 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);}@OverrIDepublic voID hIDe() { dispose();}@OverrIDepublic voID pause() {}@OverrIDepublic voID resume() {}@OverrIDepublic 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背景显示为白色所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)