Andengine activity bg off screen

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

I set 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 bg is not suitable for the screen, it has several empty spaces in both the left and right ends. How to solve this problem?

+4
source share
1 answer

BaseResolutionPolicy decides how AndEngine will handle our application display width and height based on various factors:

FillResolutionPolicy: The FillResolutionPolicy class is typical if we just want our application to take up the full width and height of the display. This can cause some noticeable stretching so that our scene covers the entire available display size.

FixedResolutionPolicy: The FixedResolutionPolicy class allows us to use a fixed display size for our application, regardless of the size of the device’s display or the size of the camera object. This policy can be passed to EngineOptions through the new FixedResolutionPolicy (pWidth, pHeight), where pWidth defines the final width, the view will span, and pHeight determines the final height, the application will span.

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

RelativeResolutionPolicy: This is the final permission policy. This policy allows us to apply scaling, both larger and smaller, to the overall appearance of the application, based on the scaling factor, with 1f being the default value.

So, if you want full-screen mode, use FillResolutionPolicy as follows:

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

Source: https://habr.com/ru/post/1496712/


All Articles