我在三星和LG上获得了不同的屏幕:
三星(应该是) ! http://www.marcofriedmann.de/right.pngLG: ! http://www.marcofriedmann.de/wrong.png
我尝试了各种视口类型,但没有改变。 有线索吗? 这是代码:
package de.marcofriedmann.slideit.screens;
import com.badlogic.gdx.Game;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Label.LabelStyle;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.Stack;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
import com.badlogic.gdx.utils.viewport.ExtendViewport;
import de.marcofriedmann.slideit.util.Assets;
import de.marcofriedmann.slideit.util.Constants;
import de.marcofriedmann.slideit.util.GameStatistics;
import de.marcofriedmann.slideit.util.IActivityRequestHandler;
public class ScoreScreen extends AbstractGameScreen {
private GameStatistics statistics;
private Stage stage;
private Skin skinSlideIt;
private Skin skinLibgdx;
private Image imgBackground;
public ScoreScreen(Game game, IActivityRequestHandler myRequestHandler,
GameStatistics statistics) {
super(game, myRequestHandler);
this.statistics = statistics;
}
private void rebuildStage() {
skinSlideIt = new Skin(Gdx.files.internal(Constants.SKIN_SLIDEIT), new TextureAtlas(Constants.TEXTURE_ATLAS_OBJECTS));
skinLibgdx = new Skin(Gdx.files.internal(Constants.SKIN_LIBGDX_UI), new TextureAtlas(Constants.TEXTURE_ATLAS_LIBGDX_UI));
Table layerBackground = buildBackgroundLayer();
Table layerControls = buildControlsLayer();
stage.clear();
Stack stack = new Stack();
stack.setFillParent(true);
stage.addActor(stack);
stack.setSize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
stack.add(layerBackground);
stack.add(layerControls);
}
private Table buildBackgroundLayer() {
Table layer = new Table();
imgBackground = new Image(skinSlideIt, "screenshot_slideit");
layer.add(imgBackground);
return layer;
}
private Table buildControlsLayer() {
LabelStyle labelTitleStyle = new LabelStyle(Assets.instance.fonts.titleFont, Color.WHITE);
LabelStyle labelNormalStyle = new LabelStyle(Assets.instance.fonts.normalFont, Color.WHITE);
LabelStyle labelNormalGreenStyle = new LabelStyle(Assets.instance.fonts.normalFont, Color.GREEN);
Table layer = new Table();
layer.setFillParent(true);
layer.top().padTop(50);
Label actualStatisticsTitle = new Label("Actual Game Statistics ", labelTitleStyle);
String actualStatisticsText1 =
"Number of seconds survived: " + statistics.actualGameStatistics.numActualSecondsSurvived +
"/" + statistics.numSecondsSurvived;
String actualStatisticsText2 =
"Number of waves survived: " + statistics.actualGameStatistics.numActualWavesSurvived +
"/" + statistics.numWavesSurvived;
String actualStatisticsText3 =
"Number of wall collisions: " + statistics.actualGameStatistics.numActualWallCollisions +
"/" + statistics.numWallCollisions;
String actualStatisticsText4 =
"Number of enemy collisions: " + statistics.actualGameStatistics.numActualEnemyCollisions +
"/" + statistics.numEnemyCollisions;
Label actualStatisticsLabel1;
if (statistics.actualGameStatistics.numActualSecondsSurvived > statistics.numSecondsSurvived) {
actualStatisticsLabel1 = new Label(actualStatisticsText1, labelNormalGreenStyle);
statistics.numSecondsSurvived = statistics.actualGameStatistics.numActualSecondsSurvived;
} else {
actualStatisticsLabel1 = new Label(actualStatisticsText1, labelNormalStyle);
}
Label actualStatisticsLabel2;
if (statistics.actualGameStatistics.numActualWavesSurvived > statistics.numWavesSurvived) {
actualStatisticsLabel2 = new Label(actualStatisticsText2, labelNormalGreenStyle);
statistics.numWavesSurvived = statistics.actualGameStatistics.numActualWavesSurvived;
} else {
actualStatisticsLabel2 = new Label(actualStatisticsText2, labelNormalStyle);
}
Label actualStatisticsLabel3;
if (statistics.actualGameStatistics.numActualWallCollisions > statistics.numWallCollisions) {
actualStatisticsLabel3 = new Label(actualStatisticsText3, labelNormalGreenStyle);
statistics.numWallCollisions = statistics.actualGameStatistics.numActualWallCollisions;
} else {
actualStatisticsLabel3 = new Label(actualStatisticsText3, labelNormalStyle);
}
Label actualStatisticsLabel4;
if (statistics.actualGameStatistics.numActualEnemyCollisions > statistics.numEnemyCollisions) {
actualStatisticsLabel4 = new Label(actualStatisticsText4, labelNormalGreenStyle);
statistics.numEnemyCollisions = statistics.actualGameStatistics.numActualEnemyCollisions;
} else {
actualStatisticsLabel4 = new Label(actualStatisticsText4, labelNormalStyle);
}
statistics.saveGameStatistics();
Label overallStatisticsTitle = new Label("Overall Game Statistics ", labelTitleStyle);
String overallStatisticsText =
"Number of games played: " + statistics.numGamesPlayed + "\n" +
"Number of seconds survived: " + statistics.numSecondsPlayedTotal + "\n" +
"Number of wall collisions: " + statistics.numWallCollisionsTotal + "\n" +
"Number of enemy collisions: " + statistics.numEnemyCollisionsTotal;
Label overallStatisticsLabel = new Label(overallStatisticsText, labelNormalStyle);
TextButton playButton = new TextButton(" Play ", skinLibgdx);
playButton.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
myRequestHandler.showAds(false);
game.setScreen(new GameScreen(game, myRequestHandler));
}
});
TextButton resetButton = new TextButton(" Reset ", skinLibgdx);
resetButton.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
statistics.actualGameStatistics.numActualEnemyCollisions = 0;
statistics.actualGameStatistics.numActualSecondsSurvived = 0;
statistics.actualGameStatistics.numActualWallCollisions = 0;
statistics.actualGameStatistics.numActualWavesSurvived = 0;
statistics.numEnemyCollisions = 0;
statistics.numEnemyCollisionsTotal = 0;
statistics.numGamesPlayed = 0;
statistics.numSecondsPlayedTotal = 0;
statistics.numSecondsSurvived = 0;
statistics.numWallCollisions = 0;
statistics.numWallCollisionsTotal = 0;
statistics.numWavesSurvived = 0;
statistics.saveGameStatistics();
rebuildStage();
}
});
layer.add(actualStatisticsTitle);
layer.add(playButton);
layer.row();
layer.add(actualStatisticsLabel1);
layer.row();
layer.add(actualStatisticsLabel2);
layer.row();
layer.add(actualStatisticsLabel3);
layer.row();
layer.add(actualStatisticsLabel4);
layer.row();
layer.add(overallStatisticsTitle);
layer.add(resetButton);
layer.row();
layer.add(overallStatisticsLabel);
return layer;
}
@Override
public void render(float deltaTime) {
Gdx.gl.glClearColor(0, 0, 0, 0);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
stage.act(deltaTime);
stage.draw();
}
@Override
public void resize(int width, int height) {
stage.getViewport().update(width, height, false);
}
@Override
public void show() {
stage = new Stage(new ExtendViewport(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()));
Gdx.input.setInputProcessor(stage);
rebuildStage();
myRequestHandler.showAds(true);
}
@Override
public void hide() {
stage.dispose();
skinSlideIt.dispose();
skinLibgdx.dispose();
}
@Override
public void pause() {
// TODO Auto-generated method stub
}
@Override
public void resume() {
// TODO Auto-generated method stub
}
@Override
public void dispose() {
// TODO Auto-generated method stub
}
}
答案 0 :(得分:0)
您的字体中的源纹理对于您正在测试的LG手机的低分辨率屏幕来说太大了。有几种方法可以解决这个问题。以下是几种选择:
getHeight()
和getWidth()
传递给实际的屏幕尺寸。相反,请为其提供您知道展示整个UI所需的最小尺寸。它将缩小以适应较小的屏幕。您可能希望将字体上的min过滤器设置为MipMapLinearNearest或MipMapLinearLinear。第二种选择在更广泛的设备上看起来更好,但可能会导致帧速率下降。磁力过滤器需要是线性的。