2014-09-28 41 views
2

我在橫向模式下運行我的應用程序時遇到了libGDX的其他很棒的scene2d ui庫問題。我的程序在Android模擬器和桌面環境中均可正常工作,但是當我在iOS模擬器或真實設備上運行它時,主菜單被繪製爲彷彿手機仍然處於縱向方向,而剛剛裁剪爲適合風景。起初,我認爲我剛剛搞砸了,因爲我還在學習api,但該應用程序的工作方式與android上的預期相同。我已將遊戲配置爲在iOS和Android上以橫向模式運行。libgdx - iOS風景與scene2d無法正常工作

在android模擬器上,菜單按預期工作。模擬器處於橫向模式,並正確顯示菜單。

在iOS上,菜單偏離中心且不可點擊。

我很確定問題與橫向模式有關,因爲在縱向方向中一切正常。這是我的MainMenuScreen代碼,它擴展了ScreenAdapter。

package bakpakin.techgame; 

import com.badlogic.gdx.Gdx; 
import com.badlogic.gdx.ScreenAdapter; 
import com.badlogic.gdx.graphics.Color; 
import com.badlogic.gdx.graphics.GL20; 
import com.badlogic.gdx.scenes.scene2d.Actor; 
import com.badlogic.gdx.scenes.scene2d.Stage; 
import com.badlogic.gdx.scenes.scene2d.ui.*; 
import com.badlogic.gdx.scenes.scene2d.ui.TextButton.TextButtonStyle; 
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener; 

/** 
* Created by Calvin on 9/25/14. 
*/ 
public class MainMenuScreen extends ScreenAdapter { 

private TechGame game; 
private Stage stage; 
private Skin skin; 
private Table table; 

public MainMenuScreen(TechGame game) { 
    this.game = game; 
} 

@Override 
public void show() { 
    this.stage = new Stage(); 
    this.skin = new Skin(); 

    skin.add("default", Assets.superScript48); 
    skin.add("title", Assets.superScript128); 

    TextButtonStyle textButtonStyle = new TextButtonStyle(); 
    textButtonStyle.font = skin.getFont("default"); 
    textButtonStyle.pressedOffsetY = 4; 
    skin.add("default", textButtonStyle); 

    Label.LabelStyle labelStyle = new Label.LabelStyle(); 
    labelStyle.font = skin.getFont("title"); 
    labelStyle.fontColor = Color.CYAN; 
    skin.add("default", labelStyle); 

    // Create a table that fills the screen. Everything else will go inside this table. 
    table = new Table(); 
    table.setFillParent(true); 
    stage.addActor(table); 

    final TextButton play = new TextButton("Play", skin); 
    final TextButton about = new TextButton("About", skin); 
    final TextButton quit = new TextButton("Quit", skin); 

    play.addListener(new ChangeListener() { 
     @Override 
     public void changed(ChangeEvent event, Actor actor) { 
      Assets.button1Sound.play(1, 1, 0); 
     } 
    }); 

    about.addListener(new ChangeListener() { 
     @Override 
     public void changed(ChangeEvent event, Actor actor) { 
      Assets.button1Sound.play(1, 1, 0); 
     } 
    }); 

    quit.addListener(new ChangeListener() { 
     @Override 
     public void changed(ChangeEvent event, Actor actor) { 
      Assets.button1Sound.play(1, 1, 0); 
      Gdx.app.exit(); 
     } 
    }); 

    final Label title = new Label("My Game", skin); 

    VerticalGroup vg = new VerticalGroup(); 

    vg.pad(60); 

    table.add(title); 
    table.row(); 
    table.add(vg); 

    vg.addActor(play); 
    vg.addActor(about); 
    vg.addActor(quit); 

    Gdx.input.setInputProcessor(stage); 
} 

@Override 
public void render(float delta) { 

    GL20 gl = Gdx.gl; 
    gl.glClearColor(0, 0, 0, 1); 
    gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT); 

    stage.act(delta); 
    stage.draw(); 
} 

@Override 
public void dispose() { 
    stage.dispose(); 
    skin.dispose(); 
} 
} 

回答

0

IOS 7或8?我聽說有一些iOS 8渲染問題

顯然這是在最新的快照中修復的(請參閱github.com/libgdx/libgdx/issues/2386)。隨着即將發佈的新版穩定版本的發佈,我相信如果你不夠勇敢地運行快照版本,我相信這個修補程序將被摺疊。

+0

使用iOS 8.0(550.1) – 2014-09-28 21:12:12