andengine活动BG不适合屏幕 [英] andengine activity bg not fit the screen

查看:150
本文介绍了andengine活动BG不适合屏幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经设置菜单页面BG用我简单的游戏开发 andengine。


  

我已经设置了BG为


 公共类MenuActivity扩展SimpleBaseGameActivity工具
    IOnMenuItemClickListener {私有静态诠释CAMERA_WIDTH = 480;
私有静态诠释CAMERA_HEIGHT = 800;私人相机mCamera;
私人ITextureRegion mBackgroundTextureRegion;受保护的静态最终诠释MENU_RESET = 0;
受保护的静态最终诠释MENU_QUIT = MENU_RESET + 1;
私人字体mFont;
保护MenuScene mMenuScene;私人场景MSCENE;
@燮pressWarnings(德precation)
@覆盖
公共EngineOptions onCreateEngineOptions(){
    最终显示显示= getWindowManager()getDefaultDisplay()。    this.mCamera =新照相机(0,0,CAMERA_WIDTH,CAMERA_HEIGHT);    返回新EngineOptions(真,ScreenOrientation.PORTRAIT_FIXED,
            新RatioResolutionPolicy(CAMERA_WIDTH,CAMERA_HEIGHT)
            this.mCamera);
}@覆盖
保护无效onCreateResources(){
    BitmapTextureAtlasTextureRegionFactory.setAssetBasePath(GFX /);
    尝试{
        ITexture backgroundTexture =新BitmapTexture(
                this.getTextureManager(),新IInputStreamOpener(){
                    @覆盖
                    公众的InputStream的open()抛出IOException
                        返回getAssets()开(GFX / bg3.png)。
                    }
                });
        backgroundTexture.load();
        this.mBackgroundTextureRegion = TextureRegionFactory
                .extractFromTexture(backgroundTexture);
    }赶上(IOException异常五){
        // TODO自动生成catch块
        e.printStackTrace();
    }
}@覆盖
保护场景onCreateScene(){
    this.mEngine.registerUpdateHandler(新FPSLogger());
    this.mScene =新场景();
    精灵backgroundSprite =新精灵(0,0,
            this.mBackgroundTextureRegion,getVertexBufferObjectManager());
    // this.mScene.attachChild(backgroundSprite);
    this.mScene.setBackground(新SpriteBackground(backgroundSprite));
    返回this.mScene;
}


  

和所述血糖不适合它在两个左和右端部分的空的空间的屏幕。
  如何解决这个问题,?



解决方案

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


  

FillResolutionPolicy:的FillResolutionPolicy类是典型的
  解决策略,如果我们只是希望我们的应用程序占用
  全宽和显示器的高度。它可能会导致一些明显的
  为了伸展我们的场景占用全部可用
  显示屏尺寸。


  
  

FixedResolutionPolicy:的FixedResolutionPolicy类允许我们
  适用于我们的应用程序固定的显示尺寸,无论大小,
  的设备的显示器或照相机对象的尺寸。此策略可
  被传递到通过new FixedResolutionPolicy EngineOptions(PWIDTH,
  pHeight),其中PWIDTH限定的最终宽度,该应用程序的
  鉴于将覆盖,并pHeight定义的最终高度的
  应用程序的视图将覆盖。


  
  

RatioResolutionPolicy:的RatioResolutionPolicy类是最好的
  为解决政策的选择,如果我们需要获得最大
  显示大小,而不会造成精灵的任何变形。在另一
  另一方面,由于广泛的Andr​​oid设备的跨越许多显示
  大小不一,有可能是某些设备可能会看到黑网吧无论是在
  在显示的顶部和底部,或左侧和右侧。


  
  

RelativeResolutionPolicy:这是最后的解决策略。这个
  政策允许我们应用缩放,或者更大或更小,以
  基于缩放因子与1F作为整体应用视图
  默认值。


所以,如果你想全屏幕,使用FillResolutionPolicy是这样的:

  EngineOptions engineOptions =新EngineOptions(真实的,
ScreenOrientation.LANDSCAPE_FIXED,新FillResolutionPolicy()
mCamera);

I have set bg for the menu page in my simple game developing using andengine.

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 decides how AndEngine will handle our application's display width and height based on various factors:

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.

So if you want full screen, use FillResolutionPolicy like this:

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

这篇关于andengine活动BG不适合屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆