Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (774)
Games in Android Showcase (230)
games submitted by our members
Games in WIP (856)
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 192 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.

1  
2  
3  
4  
    final float VIEWPORT_HEIGHT = 16.0f;

    float aspectRatio = (float)Gdx.graphics.getWidth() / (float)Gdx.graphics.getHeight();
    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  
 
 

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

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

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

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

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

nelsongames (1976 views)
2018-04-24 18:14:32

ivj94 (2743 views)
2018-03-24 14:47:39

ivj94 (1945 views)
2018-03-24 14:46:31

ivj94 (3036 views)
2018-03-24 14:43:53

Solater (1088 views)
2018-03-17 05:04:08
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

Deployment and Packaging
by philfrei
2018-08-20 02:33:38

Deployment and Packaging
by philfrei
2018-08-20 02:29:55

Deployment and Packaging
by philfrei
2018-08-19 23:56:20

Deployment and Packaging
by philfrei
2018-08-19 23:54:46
java-gaming.org 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‑gaming.org
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!