2013-05-18 3 views
3

내 배경 이미지가 나타나지 않습니다. 이렇게하면 모서리에 흰색 사각형이 나타납니다.주 메뉴의 LIBGDX 배경이 흰색으로 표시됩니다.

https://dl.dropboxusercontent.com/u/45938379/menu.png

나는 당신이 볼 수있는 내 배우가 뒤에 보이고,이 문제를 해결하는 방법을 알고 있어야합니다.

여기에 내가 뭘도 눈치 챘을하는 것은 내가

stage.draw(); 

을 제거하면 이미지가 나타나는지 내 코드

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

}

입니다.

답변

3

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

난 당신이 무대 안에 당신의 배경을 넣어 추천 할 것입니다. Image도 액터이므로 무대에 추가하고 .toBack() (Back)으로 전화를 걸어 배경에 추가 할 수 있습니다.
Libgdx Image

관련 문제