简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM