android - andengine activity bg 不适合屏幕

标签 android andengine

我在使用 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/

相关文章:

android - 等待和引擎的功能?

android - AndEngine中的手绘物理对象

android - 和引擎错误

c# - 如何重新生成 Resource.designer.cs 文件 Xamarin Android

java - Android SQLite : How to search by second word in value?

android - 如何从后台弹出 fragment

android - 在 DatePicker 中调用两次的方法

android - 没有测试的模块中的 "No tests found"错误

android - 无法将 child 附加到场景

java - NullPointerExceptionProblem - 使用 Eclipse 和 AndEngine 进行 OUYA 开发