1
當我運行我的應用程序的Android版本時,使用位圖繪製的文本顯示在我的桌面版本中的(方式)不同位置上,而不是我的Android版本的應用程序中。我已經看過這個問題,並且讀到我必須將Projectmatrix設置爲合併,但這沒有幫助。不知道什麼原因可能是跨平臺顯示不同位置的文本。LIBGDX字體在不同平臺上的不同位置
public class HighScoresScreen implements Screen{
private CrossplatformApp game;
private Stage stage;
private TextButton backButton;
private OrthographicCamera camera;
private Table table;
BitmapFont font = new BitmapFont();
private Skin skin;
private Texture background;
private String[] data;
private String[] playerscores;
String nm = "";
String sc = "";
public HighScoresScreen (CrossplatformApp game) {
this.game = game;
this.camera = new OrthographicCamera(Constants.WIDTH, Constants.HEIGHT);
this.camera.position.set(Constants.WIDTH/2, Constants.HEIGHT/2, 0);
this.camera.update();
game.batch.setProjectionMatrix(this.camera.combined);
this.skin = new Skin(Gdx.files.internal("skin/uiskin.json"));
this.background = new Texture("Screens/HighscoresScreen/highscores.png");
}
@Override
public void show() {
backButton = new TextButton("back", skin);
backButton.addListener(new ClickListener(){
@Override
public void clicked(InputEvent event, float x, float y) {
game.setScreen(new MenuScreen(game));
MenuScreen.musicHandler.stopMusic();
}
});
Gdx.input.setInputProcessor(stage);
JSONfunctions json = new JSONfunctions();
parseJSON parse = new parseJSON(json.doInBackground());
for (String i : parse.getNames()){
if(i != null) {
nm += i;
nm += "\n\n";
} else {
break;
}
}
System.out.println(nm);
//
for (String i : parse.getScores()){
if(i != null) {
sc += i;
sc += "\n\n";
} else {
break;
}
}
table = new Table();
table.setFillParent(true);
table.bottom();
table.add(backButton).size(100, 100);
stage.addActor(table);
}
@Override
public void render(float delta) {
game.batch.begin();
game.batch.draw(background, 0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
font.draw(game.batch, nm, 100, 300);
font.draw(game.batch, sc, 480, 300);
game.batch.end();
}
@Override
public void resize(int width, int height) {
}
@Override
public void pause() {
}
@Override
public void resume() {
}
@Override
public void hide() {
}
@Override
public void dispose() {
stage.dispose();
}
}
您是否嘗試使用視口? – Expiredmind
@Expiredmind是我有,像這樣:'this.camera = new OrthographicCamera(); this.stage = new Stage(new FillViewport(Constants.WIDTH,Constants.HEIGHT,camera));'然後在渲染方法中繪製這個舞臺 – Vitalynx
我認爲你可以使用'Label'然後將它添加到舞臺上。然後你可以刪除'font.draw'。舞臺中的「視口」可以很好地處理不同的分辨率。 – Expiredmind