coder_For_Life22
coder_For_Life22

Reputation: 26971

How to decide width and height for SVG sprite in AndEngine

I am using AndEngine to load a svg images as my Sprites.

The problem I am having with this is that i can't figure out how to scale the image to fit the particular device on which it is being run.

sprite= new Sprite(positionX, positionY, WIDTH,HEIGHT,TextureRegion);

The parameters that it takes are the position's on x and y coordinates, and then width, and height.

The problem I am having is that I can't figure out how to scale the sprite to the right width and height for how I want it.

For example I have a title, and I want the title to be bigger on bigger devices, how would I decide if the device is bigger and scale it up for a bigger screen and down for a smaller screen?

Upvotes: 2

Views: 1408

Answers (1)

Jong
Jong

Reputation: 9115

If you use a constant camera size, all of the screen is scaled (Hence all of the entities).

Decide on a constant size, for exaple 720x480.

final static int CAMERA_WIDTH = 720;
final static int CAMERA_HEIGHT = 480;

Then, when creating the engine options, use:

... new EngineOptions(... new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), ...);

On each device, the camera will scale itself to fit the resolution as good possible, while keeping the ratio between width & height. Now, when creating a sprite, just do:

Sprite sprite = new Sprite(x, y, TextureRegion);

Don't give the sprite size! Its size comparing to the camera size will be decided according to the texture region size, and it will be a constant one. Then, it will be scaled by the camera-to-device-screen scaling, which changes from one device to another, but the ratio will remain constant - the game will not look like a bad scaled image on devices with a different resoltuion that the camera width/height ratio.

I think that's a great method that AndEngine provides to deal with different screen resolution; IMHO, it is the best to use.

Upvotes: 5

Related Questions