4

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

Tamilselvan Kalimuthu
  • 1,534
  • 1
  • 13
  • 28

1 Answers1

10

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);
Sushil
  • 8,250
  • 3
  • 39
  • 71
  • i am changing to different ratios but not fit to the screen. is there any ratio or default values there for this? – Tamilselvan Kalimuthu Aug 13 '13 at 06:16
  • am not very sure about this. but you width always gets adjusted based on height in landscape. So, better to leave that space you want to keep aspect ratio intact. Else, just increase the width to fit your screen. It shouldn't bother much. – Sushil Aug 13 '13 at 06:18
  • well this can be the reason but my i didnt get clear solution about this bg and its scaling with the camera width and height. thanks for ur information.+1 for ur information. – Tamilselvan Kalimuthu Aug 13 '13 at 06:22
  • Whatever you see on the screen is your camera view. Just imagine that a camera is placed on top of your screen and you are seeing through camera. Then cameraview is transformed to screenview. So whatever you see on screen is based on camera position and width and height. We need this coz in case you move the camera, you can get the feel of moving background and all. I mean parallax background. – Sushil Aug 13 '13 at 06:29
  • I have updated my answer to give correct reasoning and solution for your problem. Please accept it if you feel its correct. – Sushil Aug 29 '13 at 02:50