Aziz
Aziz

Reputation: 1614

Andengine Android Game resizing sprites with respect to screen size?

So I need to resize my sprites with respect to the phones screen size,

I do the following:

final Display display = getWindowManager().getDefaultDisplay();
    cameraWidth = display.getWidth();
    cameraHeight = display.getHeight();
    //check to load male or female
    Intent sender=getIntent();
    String extraData=sender.getExtras().getString("char");
    if(extraData.contains("1"))
    {
        isMale = 1;
    }
    else
    {
        isMale = 0;
    }

    mCamera = new Camera(0, 0, cameraWidth, cameraHeight);
    return new Engine(new EngineOptions(true, ScreenOrientation.LANDSCAPE,
            new RatioResolutionPolicy(cameraWidth, cameraHeight), mCamera)
            .setNeedsMusic(true).setNeedsSound(true));

However, for sprites, ie the player and enemies, I give them an arbitrary size such as 50 pix by 50pix - Now on small screens they appear really large! how can I resize them with respect to the screen size?

Also, These images are loaded from assets folder, so they have nothing to do with HDPI and LHPI image folders.

Thanks in advance community.

Upvotes: 0

Views: 3468

Answers (1)

coder_For_Life22
coder_For_Life22

Reputation: 26971

You should either use SVG graphics that are scalable on different device screens.

What i would suggest is you set the CAMERA_WIDTH and HEIGHT to a screen size no matter what size device it is on.

For example, for a project i am making i have a camera width and height of 800x480.

This way you dont have to worry about resizing any sprites. They all appear the same on each device while scaling up by the engine with the RationResolutionPolicy.

This is the best way to go about this.

If you set the screens size based on the device you will have to supple different graphics for each.

So i would recommend using SVG graphics so that when the images are scaled up automatically by the engine they dont loose quality. OR you can use png's and make them large, that way they will only be scaled down. And as you know they wont lose image quality by scaling down.

Upvotes: 2

Related Questions