我正在制作基于Libgdx
框架的Box2D游戏。
当我从MenuScreen
导航到GameScreen
我的GameScreen
旋转180度。
我谷歌,但我找不到任何解决方案。
这是我的代码:
Menuscreen:
private static final String TAG = MenuScreen.class.getName();
private Stage stage;
private Skin skinMenuScreen;
//private Skin skinLibgdx;
// menu
private Image imgBackground;
private Image imgControlContainer;
private TextButton btnStartGame;
// debug
private final float DEBUG_REBUILD_INTERVAL = 5.0f;
private boolean debugEnabled = false;
private float debugRebuildStage;
public MenuScreen(Game game) {
super(game);
//onStartClicked();
}
@Override
public void render(float deltaTime) {
Gdx.gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
//rebuildStage();//you rebuild your stage inside render method?
stage.act(deltaTime);
stage.draw();
}
@Override
public void resize(int width, int height) {
stage.getViewport().update(width, height);
}
@Override
public void show() {
stage = new Stage();
Gdx.input.setInputProcessor(stage);
rebuildStage();
}
@Override
public void hide() {
stage.dispose();
skinMenuScreen.dispose();
//skinLibgdx.dispose();
}
@Override
public void pause() {
}
private void rebuildStage () {
skinMenuScreen = new Skin(Gdx.files.internal(AppConstant.SKIN_MENU_SCREE_UI), new TextureAtlas(AppConstant.TEXTURE_ATLAS_UI));
//skinLibgdx = new Skin(Gdx.files.internal(AppConstant.SKIN_LIBGDX_UI), new TextureAtlas(AppConstant.TEXTURE_ATLAS_LIBGDX_UI));
// build all layers
Table layerBackground = buildBackgroundLayer();
Table layerContolContainer = buildCantainer();
Table layerStartControls = buildStartControlsLayer();
// assemble stage for menu screen
stage.clear();
Stack stack = new Stack();
stage.addActor(stack);
stack.setSize(AppConstant.VIEWPORT_GUI_WIDTH, AppConstant.VIEWPORT_GUI_HEIGHT);
stack.add(layerBackground);
stack.add(layerContolContainer);
stack.add(layerStartControls);
}
private Table buildBackgroundLayer () {
Table layer = new Table();
// + Background
imgBackground = new Image(skinMenuScreen, "welcome");
layer.add(imgBackground);
return layer;
}
private Table buildTitle()
{
Table layer = new Table();
layer.center().top();
layer.padTop(40);
// + Title
BitmapFont bitmapFont = Assets.instance.fonts.bitmapFont;
LabelStyle lblStyle = new LabelStyle(bitmapFont, Color.WHITE);
lblTitle= new Label("Jungle Monkey", lblStyle);
layer.add(lblTitle);
return layer;
}
private Table buildStartControlsLayer()
{
Table layer = new Table();
// + Sound
TextButtonStyle textButtonStyle = new TextButtonStyle();
BitmapFont bitmapFont = Assets.instance.fonts.bitmapFont;
textButtonStyle.font = bitmapFont;
textButtonStyle.fontColor = Color.DARK_GRAY;
bitmapFont.setScale(1.0F);
textButtonStyle.up = skinMenuScreen.getDrawable("menu-2");
textButtonStyle.down = skinMenuScreen.getDrawable("menu-2");
btnStartGame = new TextButton("Start", textButtonStyle);
layer.addActor(btnStartGame);
btnStartGame.setPosition((AppConstant.VIEWPORT_GUI_WIDTH - 230), 100);
btnStartGame.setSize(150, 50);
btnStartGame.addListener(new ChangeListener() {
@Override
public void changed (ChangeEvent event, Actor actor) {
onStartClicked();
}
});
layer.add(btnStartGame);
return layer;
}
private void onStartClicked()
{
System.out.println("clicked");
game.setScreen(new GameScreen(game));
System.out.println("clicked");
}
@Override
public InputProcessor getInputProcessor() {
return null;
}
GameScreen
public class GameScreen extends AbstractGameScreen
{
private static final String TAG = GameScreen.class.getName();
private WorldController worldController;
private WorldRenderer worldRenderer;
private boolean paused;
public GameScreen(Game game) {
super(game);
}
@Override
public void render(float deltaTime) {
// Do not update game world when paused.
if (!paused) {
// Update game world by the time that has passed
// since last rendered frame.
worldController.update(deltaTime);
}
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
// Render game world to screen
worldRenderer.render();
}
@Override
public void resize(int width, int height) {
worldRenderer.resize(width, height);
}
@Override
public void show() {
worldController = new WorldController(game);
worldRenderer = new WorldRenderer(worldController);
}
@Override
public void hide() {
worldRenderer.dispose();
}
@Override
public void pause() {
paused = true;
}
@Override
public void resume () {
super.resume();
// Only called on Android!
paused = false;
}
@Override
public InputProcessor getInputProcessor () {
return worldController;
}
}
感谢任何帮助。 感谢。