gpt4 book ai didi

android - andengine activity bg 不适合屏幕

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:53:59 25 4
gpt4 key购买 nike

我在使用 andengine. 开发的简单游戏中为菜单页面设置了 bg

I have Set the bg as

public class MenuActivity extends SimpleBaseGameActivity implements
IOnMenuItemClickListener {

private static int CAMERA_WIDTH = 480;
private static int CAMERA_HEIGHT = 800;

private Camera mCamera;
private ITextureRegion mBackgroundTextureRegion;

protected static final int MENU_RESET = 0;
protected static final int MENU_QUIT = MENU_RESET + 1;
private Font mFont;
protected MenuScene mMenuScene;

private Scene mScene;


@SuppressWarnings("deprecation")
@Override
public EngineOptions onCreateEngineOptions() {
final Display display = getWindowManager().getDefaultDisplay();

this.mCamera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);

return new EngineOptions(true, ScreenOrientation.PORTRAIT_FIXED,
new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT),
this.mCamera);
}

@Override
protected void onCreateResources() {
BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/");


try {
ITexture backgroundTexture = new BitmapTexture(
this.getTextureManager(), new IInputStreamOpener() {
@Override
public InputStream open() throws IOException {
return getAssets().open("gfx/bg3.png");
}
});
backgroundTexture.load();
this.mBackgroundTextureRegion = TextureRegionFactory
.extractFromTexture(backgroundTexture);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}


}

@Override
protected Scene onCreateScene() {
this.mEngine.registerUpdateHandler(new FPSLogger());
this.mScene = new Scene();
Sprite backgroundSprite = new Sprite(0, 0,
this.mBackgroundTextureRegion, getVertexBufferObjectManager());
// this.mScene.attachChild(backgroundSprite);
this.mScene.setBackground(new SpriteBackground(backgroundSprite));


return this.mScene;
}

and the bg is not fit to the screen it has some empty spaces in both left and right ends. How to solve this,?

最佳答案

BaseResolutionPolicy 决定 AndEngine 如何处理我们应用程序的显示宽度和基于各种因素的高度:

FillResolutionPolicy: The FillResolutionPolicy class is the typical resolution policy if we simply want our application to take up the full width and height of the display. It may cause some noticeable stretching in order for our scene to take up the full available dimensions of the display.

FixedResolutionPolicy: The FixedResolutionPolicy class allows us to apply a fixed display size for our application, regardless of the size of the device's display or Camera object dimensions. This policy can be passed to EngineOptions via new FixedResolutionPolicy(pWidth, pHeight), where pWidth defines the final width that the application's view will cover, and pHeight defines the final height that the application's view will cover.

RatioResolutionPolicy: The RatioResolutionPolicy class is the best choice for resolution policies if we need to obtain the maximum display size without causing any distortion of sprites. On the other hand, due to the wide range of Android devices spanning many display sizes, it is possible that some devices may see "black bars" either on the top and bottom, or left and right sides of the display.

RelativeResolutionPolicy: This is the final resolution policy. This policy allows us to apply scaling, either larger or smaller, to the overall application view based on a scaling factor with 1f being the default value.

因此,如果您想要全屏,请像这样使用 FillResolutionPolicy:

EngineOptions engineOptions = new EngineOptions(true,
ScreenOrientation.LANDSCAPE_FIXED, new FillResolutionPolicy(),
mCamera);

关于android - andengine activity bg 不适合屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18201244/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com