Note that there are some explanatory texts on larger screens.

plurals
  1. POProperly scaling or resizing an image or sprite maintaining its original aspect ratio
    primarykey
    data
    text
    <p>I have gone through a lot of answers in this site but unfortunately nothing solves the problem I am about to describe.</p> <p>I have designed an app with 800x520 in landscape mode. All assets are designed using that predefined window size. I used unit system but I think that's irrelevant here.</p> <p>Now, I have a sprite/image that is 85x70 in size. I want it to scale but maintaining its original aspect ratio no matter what the window/screen size of the real device is. I have the following so far, which keeps the ratio but doesn't resize properly meaning if the device screen is bigger than my predefined window size by both width and height, it shows the sprite still small. If there's no change in height but only in width or no change in width but only in height, then that's fine. The image should not be scaled on x or y. But this snippet below doesn't do the job.</p> <pre><code>float screenW = Screen.SCREEN_WIDTH; // Predefined width 800 float screenH = Screen.SCREEN_HEIGHT; // Predefined height 520 float deviceW = Gdx.graphics.getWidth(); // Actual device width that can vary float deviceH = Gdx.graphics.getHeight(); // Actual device height that can vary float changeX = screenW / deviceW; // Also tried deviceW / screenW float changeY = screenH / deviceH; // Also tried deviceH / screenH // I tried applying the changeX and changeY above // in sprite's scale.x and scale.y respectively but no luck // So I tried the below to get the new size of the sprite // with and without applying scale above.. // Tried a lot of ways but no luck float newWidth = (Sprite.WIDTH * changeX); float newHeight = (Sprite.HEIGHT * changeY); </code></pre> <p>I do not need any actual code as long as I have a correct algo, I'd appreciate it.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload