2016-05-27 27 views
0

我的代码运行这样的:LibGDX如何缩放图像的每一个设备

public class MainMenuOptions extends AbstractScreen { 

private Texture newGameButton; 
private Texture exitGameButton; 
private Texture highScoresButton; 
private Texture background; 


public MainMenuOptions(FallingPeopleMain game) { 
    super(game); 
    init(); 
} 

private void init() { 
    newGameButton = new Texture("newGameButton.jpg"); 
    exitGameButton = new Texture("exitGameButton.jpg"); 
    highScoresButton = new Texture("highScoresGameButton.jpg"); 
    background = new Texture("BG.png"); 

} 

@Override 
public void render(float delta) { 
    spriteBatch.begin(); 
    spriteBatch.draw(background, 0, 0); 
    spriteBatch.draw(newGameButton, 180, 380); 
    spriteBatch.draw(highScoresButton, 180, 340); 
    spriteBatch.draw(exitGameButton, 180, 300); 

    spriteBatch.end(); 

} 

}

但是,当我玩我的设备华为P8精简版的看起来很垃圾40%的屏幕设备上。如何衡量一切以求好?

我已经宽度和高度上声明主类

回答

0
@Override 
public void render(float delta) { 
    float widthScale = Gdx.graphics.getWidth()/originalWidth; 
    float heightScale = Gdx.graphics.getHeight()/originalHeight; 
    spriteBatch.begin(); 
    spriteBatch.draw(background, 0, 0, background.getWidth() * widthScale, background.getHeight() * heightScale); 
    spriteBatch.draw(newGameButton, 180, 380, newGameButton.getWidth() * widthScale, newGameButton.getHeight() * heightScale); 
    spriteBatch.draw(highScoresButton, 180, 340, highScoresButton.getWidth() * widthScale, highScoresButton.getHeight() * heightScale); 
    spriteBatch.draw(exitGameButton, 180, 300, exitGameButton.getWidth() * widthScale, exitGameButton.getHeight() * heightScale); 

    spriteBatch.end(); 

} 

originalWidth和originalHeight是您的桌面(开发)版本的宽度和高度(即使它们是一样的实际宽度和高度,宣布他们分别无论如何 - 这只会意味着纹理显示原尺寸)。 originalWidth和originalHeight之间的比例必须是9:16(720x1280/360x640 ...)或16:9。

+0

认为这将帮助我,但我需要在AndroidLauncher中配置工作?在桌面上,我有Height = 720 Width = 480 – Andrzej1991

+0

720x480不是16:9,请尝试640x360并妥善放置您的资产。 – WonderfulWorld

0

你在你的清单文件中正确设置屏幕方向?如果您只希望应用程序以“站立模式”运行,请在您的清单中设置android:screenOrientation等于"portrait"。如果您希望您的应用程序以“放下模式”运行,请将其设置为"landscape"

希望这会有所帮助。 :)

+0

是啊,我知道:) – Andrzej1991