【发布时间】:2015-10-14 17:18:17
【问题描述】:
我正在学习 libgdx (java) 游戏编程,我刚刚完成了我的第一个游戏:一个简单的 Brick Destroyer。
我做了一个桌面和安卓项目。经过几个小时的“艰苦”工作,我的游戏终于在桌面上运行良好。我没有在这个游戏中使用 scene2D 或 box2D 或其他任何东西(我只是在我的类上实现了界面“屏幕”:GameScreen、MainMenuScreen 等......)。
问题是:当我将游戏导出为 .APK 文件,然后将其安装到我的 Android 手机(Sony Xperia Z1 compact)上时,屏幕完全不同。球仍然与所有其他元素(屏幕的砖块和侧面)反应良好,但它似乎不是相同的缩放。我已经尝试了很多东西,我不知道该怎么办了,请帮助我:)。
我正在使用 FitViewport 和正交相机。
请看下面的截图: 1 - GameScreen 类的构造函数。 2 - 桌面程序。 3 - 安卓应用。
谢谢大家的回答,如果我犯了错误,请原谅我的英语(我不是以英语为母语的人)。
final Bricks game;
Texture ball_img, plate_img, brique_img_rouge, brique_img_orange, brique_img_vert;
Vector2 posb, posp;
Vector2 vitb, vitp;
OrthographicCamera camera;
Rectangle ball, plate;
Array<Brique> briques;
FitViewport viewport;
final int plate_width = 60, plate_height = 10;
final int brique_width = 35, brique_height = 15;
final int ball_width = 15, ball_height = 14;
boolean left_p, right_p, up_p;
public GameScreen(final Bricks gam) {
this.game = gam;
ball_img = new Texture("ball_bl.PNG");
plate_img = new Texture("plate_bl.PNG");
brique_img_rouge = new Texture("brique_bl_rouge.PNG");
brique_img_orange = new Texture("brique_bl_orange.PNG");
brique_img_vert = new Texture("brique_bl_vert.PNG");
camera = new OrthographicCamera();
viewport = new FitViewport(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), camera);
viewport.apply();
ball = new Rectangle();
plate = new Rectangle();
briques = new Array<Brique>();
briques.add(new Brique(2));
briques.first().x = 50;
briques.first().y = Gdx.graphics.getHeight()-60;
briques.first().width = brique_width;
briques.first().height = brique_height;
posb = new Vector2(Gdx.graphics.getWidth()/2, Gdx.graphics.getHeight()/4);
vitb = new Vector2(0, 400*Gdx.graphics.getDeltaTime());
posp = new Vector2(Gdx.graphics.getWidth()/2 - plate_width/2, 20);
vitp = new Vector2(400*Gdx.graphics.getDeltaTime(), 0);
for (int i = 1; i < 65; i++) {
if( i % 13 == 0) {
briques.add(new Brique(1));
briques.get(i).x = briques.first().x;
briques.get(i).y = briques.get(i-1).y - 35;
briques.get(i).width = brique_width;
briques.get(i).height = brique_height;
} else {
briques.add(new Brique(1));
briques.get(i).x = briques.get(i-1).x + briques.get(i-1).width + 20;
briques.get(i).y = briques.get(i-1).y;
briques.get(i).width = brique_width;
briques.get(i).height = brique_height;
}
if(i > 51 || i == 19 || i == 32) {
briques.get(i).setType(3);
}
if((i < 13 || i %13 == 0 || i == 25 || i >= 38) && i < 52) {
briques.get(i).setType(2);
}
}
ball.x = posb.x;
ball.y = posb.y;
ball.width = ball_width;
ball.height = ball_height;
plate.x = posp.x;
plate.y = posp.y;
plate.width = plate_width;
plate.height = plate_height;
我认为问题来自这里,但它适用于桌面。
camera = new OrthographicCamera();
viewport = new FitViewport(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), camera);
viewport.apply();
【问题讨论】: