Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

andengine activity bg not fit the screen

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,?

like image 525
Tamilselvan Kalimuthu Avatar asked Dec 25 '22 22:12

Tamilselvan Kalimuthu


1 Answers

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);
like image 110
Sushil Avatar answered Dec 28 '22 10:12

Sushil