我在使用andengine开发的简单游戏中为菜单页面设置了bg .
我把bg设为
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;
}
Run Code Online (Sandbox Code Playgroud)
并且bg不适合屏幕,左右两端都有一些空格.怎么解决这个,?
Sus*_*hil 10
BaseResolutionPolicy决定AndEngine如何根据各种因素处理应用程序的显示宽度和高度:
FillResolutionPolicy:如果我们只是希望我们的应用程序占据显示器的整个宽度和高度,则FillResolutionPolicy类是典型的解析策略.它可能会导致一些明显的拉伸,以便我们的场景占据显示器的全部可用尺寸.
FixedResolutionPolicy: FixedResolutionPolicy类允许我们为应用程序应用固定的显示大小,无论设备的显示大小或Camera对象的尺寸如何.此策略可以通过新的FixedResolutionPolicy(pWidth,pHeight)传递给EngineOptions,其中pWidth定义应用程序视图将覆盖的最终宽度,pHeight定义应用程序视图将覆盖的最终高度.
RatioResolutionPolicy:如果我们需要获得最大显示大小而不会导致精灵失真,则RatioResolutionPolicy类是解析策略的最佳选择.另一方面,由于跨越多种显示尺寸的各种Android设备,一些设备可能在显示器的顶部和底部或左侧和右侧看到"黑条".
RelativeResolutionPolicy:这是最终解决策略.此策略允许我们基于比例因子将更大或更小的缩放应用于整个应用程序视图,其中1f是默认值.
因此,如果您想要全屏,请使用FillResolutionPolicy,如下所示:
EngineOptions engineOptions = new EngineOptions(true,
ScreenOrientation.LANDSCAPE_FIXED, new FillResolutionPolicy(),
mCamera);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1895 次 |
| 最近记录: |