Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (789)
Games in Android Showcase (234)
games submitted by our members
Games in WIP (864)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Libgdx -2D Tile game - Scaling images with resolution?  (Read 1018 times)
0 Members and 1 Guest are viewing this topic.
Offline GustavXIII

Junior Devvie

Projects: 1

« Posted 2018-11-09 11:20:15 »

If I am using all my graphics for 1024x768 resolution,  how can I make it so that if I change the resolution, my images scale up/down in the correct ratio?
I know how to do it with images who fill out the whole screen with Gdx.getScreenWidth etc.
But how can I scale the smaller images like enemies etc?

Another thing, how do I keep the viewsize of my game the same? I draw my map from 2D int Array. Tiles are 64x64 big.
With 1024x768 resolution I can look like 15 tiles left and right. 8 tiles up and down.

But if I change resolution to 1920x1080 I can watch like 30 tiles around the player. I want thatthe vision radius stays the same as in standart resolution so its fair for everyone.
Offline bmanmcfly
« Reply #1 - Posted 2018-11-10 23:48:34 »

There's a few different strategies you can use.

The ideal is to have 2-3 sizes of images, then based off the screen size and pixel density choose the best image and then its a minimal stretch to fill the screen.

What I've mostly done has been to pick a base resolution that is somewhere in the middle.
Then, do the calculation for widescreen or portrait
then, calculate the Xratio, and the Y ratio
then use one or the other ratio to scale the image sizes

Since your display is all on the assumption of the base resolution it scales.
Offline LiquidNitrogen
« Reply #2 - Posted 2018-11-11 00:44:36 »

I find its best not to work in pixel sizes.. I make a camera which is 16 units tall, and X units wide - where X is enough to fit the screen width for the aspect ratio.

    final float VIEWPORT_HEIGHT = 16.0f;

    float aspectRatio = (float) / (float);
    cam = new OrthographicCamera(VIEWPORT_HEIGHT * aspectRatio, VIEWPORT_HEIGHT);

Now since the camera is always 16 units tall, if I draw a sprite with a size of {1, 1}, I can be certain that the sprite will fill 1/16th of the vertical size of the screen no matter what the actual display resolution is.

The only remaining problem is dealing with choosing appropriate sizes for the actual assets to minimize any visible scaling artifacts, since its not likely that anything will ever be rendered at a 1:1 pixel ratio.
Pages: [1]
  ignore  |  Print  

hadezbladez (2608 views)
2018-11-16 13:46:03

hadezbladez (933 views)
2018-11-16 13:41:33

hadezbladez (2561 views)
2018-11-16 13:35:35

hadezbladez (503 views)
2018-11-16 13:32:03

EgonOlsen (3681 views)
2018-06-10 19:43:48

EgonOlsen (4057 views)
2018-06-10 19:43:44

EgonOlsen (2444 views)
2018-06-10 19:43:20

DesertCoockie (3250 views)
2018-05-13 18:23:11

nelsongames (3322 views)
2018-04-24 18:15:36

nelsongames (4292 views)
2018-04-24 18:14:32
Java Gaming Resources
by philfrei
2019-05-14 16:15:13

Deployment and Packaging
by philfrei
2019-05-08 15:15:36

Deployment and Packaging
by philfrei
2019-05-08 15:13:34

Deployment and Packaging
by philfrei
2019-02-17 20:25:53

Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!