4K support, easy way to check monitor resolution (and physics)

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
User avatar
darkfrei
Party member
Posts: 1169
Joined: Sat Feb 08, 2020 11:09 pm

4K support, easy way to check monitor resolution (and physics)

Post by darkfrei »

Hi all!

I have a 4K monitor and the gamedeving with the default window 800x600 is pretty hard. So, I use the window size at least the FullHD (windowed), but by release I can forget to change it for something compatible to monitors with resolution 1366x768.


Available resolutions:

Code: Select all

modes = love.window.getFullscreenModes()
for i, v in pairs (modes) do
	print (i..'	width : '..v.width..' height: '..v.height)
end

Code: Select all

1	width : 3840 height: 2160
2	width : 2560 height: 1600
3	width : 2560 height: 1440
4	width : 2048 height: 1536
5	width : 1920 height: 1440
6	width : 1920 height: 1200
7	width : 1920 height: 1080
8	width : 1768 height: 992
9	width : 1680 height: 1050
10	width : 1600 height: 1200
11	width : 1600 height: 1024
12	width : 1600 height: 900
13	width : 1440 height: 900
14	width : 1366 height: 768
15	width : 1360 height: 768
16	width : 1280 height: 1024
17	width : 1280 height: 960
18	width : 1280 height: 800
19	width : 1280 height: 768
20	width : 1280 height: 720
21	width : 1176 height: 664
22	width : 1152 height: 864
23	width : 1024 height: 768
24	width : 800 height: 600
25	width : 720 height: 576
26	width : 720 height: 480
27	width : 640 height: 480
How to make the same physics for any resolution?

It would be nice to detect the 4K or less-than-FullHD displays and adjust graphics/physics to it.
Last edited by darkfrei on Sat Jul 17, 2021 8:43 pm, edited 1 time in total.
:awesome: in Lua we Löve
:awesome: Platformer Guide
:awesome: freebies
User avatar
GVovkiv
Party member
Posts: 668
Joined: Fri Jan 15, 2021 7:29 am

Re: 4K support, easy way to check monitor resolution (and physics)

Post by GVovkiv »

What do you mean by "same phisics for any resolution"?
like, how screen resolution should affect phisics and staff?
It may be broke some visual, for example, if in-game map was desiged for 800/600 resolution, but you forgot to update details for 1024/600, etc where some objects may be apperead on screen when it shouldn't and other things like that, but phisics?
May you provide example or somethings because i don't uderstand the problem
User avatar
GVovkiv
Party member
Posts: 668
Joined: Fri Jan 15, 2021 7:29 am

Re: 4K support, easy way to check monitor resolution (and physics)

Post by GVovkiv »

And, just to be sure, this game uses scaling to work or it just change window size or what actually happens?
User avatar
darkfrei
Party member
Posts: 1169
Joined: Sat Feb 08, 2020 11:09 pm

Re: 4K support, easy way to check monitor resolution (and physics)

Post by darkfrei »

GVovkiv wrote: Sat Jul 17, 2021 8:35 pm May you provide example or somethings because i don't uderstand the problem
Normally we have physics like

Code: Select all

vx = vx + dt*ax
x = x + dt*vx
Where the vx is in pixels per second, x is in pixels. But on the 4K display the distance love.graphics.getWidth() is twice higher than on FullHD.
So, the graphics must be scaled up, the physics too.
If earlier on FullHD the tile was 100 pixels, the new one must be 200 pixels. Also the vx must be changed from 100 pixels/second to 200 pixels/second.
And we are need to fix the gravity! It must be something like square/square root of that new grid size, it must be somehow adjusted to new window resolution.
And scale up all collisions, graphics too.
:awesome: in Lua we Löve
:awesome: Platformer Guide
:awesome: freebies
User avatar
GVovkiv
Party member
Posts: 668
Joined: Fri Jan 15, 2021 7:29 am

Re: 4K support, easy way to check monitor resolution (and physics)

Post by GVovkiv »

I guess, you want to fix wrong problem
In 2d games, game resolution can be pretty problematic, since differen screen sizes can create lots of problems
Normally, if your game don't really care about distortion of graphics by scaling, you can simply use aspect ratio scaling to deal with that staff
You don't need to adjust about phisics or balance, just lets user pick resolution and adjust UI staff to that size
(and optimization staff, that don't render staff if it outside of camera and maybe some visual effects, for example, scrolling for 2d games, which may be easly fixed without mambo-jambo code in most cases)
If your game have pixel graphics and you don't want to distortion it with non-integer scaling, you may try something like this:

Code: Select all

	scale = math.floor(userPickedResolution / 1000) --it's not perfect formula, maybe better to take in account and width and height, but as example, it okay
	if scale < 1 than scale = 1 end
	-- so, based on user picked resolution, you will have something like:
	-- if width == 1000 or lower, you will have 1, if width => 3000 and < 4000 then 3, etc
	-- or maybe don't use resolution at all and just let user to pick scaling factor manually, without resolution, and you will be fine
	-- For example, there exist game Shattered Pixel Dungeon (https://shatteredpixel.com/) or original game Pixel Dungeon
	-- Game just uses whatewer you game size is based on window resolution and user just picks need scaling
	-- So, graphics don't distortion and user can freely pick scaling whatever they thinks is better for them
User avatar
GVovkiv
Party member
Posts: 668
Joined: Fri Jan 15, 2021 7:29 am

Re: 4K support, easy way to check monitor resolution (and physics)

Post by GVovkiv »

And scale up all collisions, graphics too.
Nope, if you using scaling, it don't
If you using actual window size, without scaling, but instead changing the actual texture somehow (maybe you use resourse packs for different resolutions, i don't know) than yes, it will change
You scaling the graphics, not the actual game
Only real collisions may change, if you use mouse
Then, yeah, scaling in game where you use mouse may hurts, since when you change scaling, you should to deal with changed images size, so you should to take in account image scaling, size, position and if you use correct aspect-ration method you also should remeber about black bars offset
User avatar
GVovkiv
Party member
Posts: 668
Joined: Fri Jan 15, 2021 7:29 am

Re: 4K support, easy way to check monitor resolution (and physics)

Post by GVovkiv »

But if you absolute mad man, you can, instead of graphics, scale the entire game, which, i guess, maybe really bad for optimization, amount of code will be more, and in overall game will be harder to develop
And it looks, like you want to go that way
User avatar
pgimeno
Party member
Posts: 3544
Joined: Sun Oct 18, 2015 2:58 pm

Re: 4K support, easy way to check monitor resolution (and physics)

Post by pgimeno »

darkfrei wrote: Sat Jul 17, 2021 8:50 pm Normally we have physics like

Code: Select all

vx = vx + dt*ax
x = x + dt*vx
Where the vx is in pixels per second, x is in pixels.
No, it's in units per second. You decide the units. Even the drawing functions are not always in pixels.

I guess what you need is some kind of manual handling of "DPI" scaling. Something like what Android does automatically, but by hand. Sadly, we don't have something like love.physics.setMeter but for love.graphics instead of love.physics, so you'll have to do it yourself. One option is to write wrappers for the system functions and apply multipliers where adequate.

For example:

Code: Select all

PPU = 4 -- pixels per unit - adjust this depending on screen size

function wrapper.draw(drawable, quad, x, y, r, sx, sy, ox, oy, kx, ky)
  if type(quad) == "nil" then
    return love.graphics.draw(drawable)
  end
  if type(quad) == "number" then
    x, y, r, sx, sy, ox, oy, kx, ky = quad, x, y, r, sx, sy, ox, oy, kx
  end
  if type(quad) == "userdata" and quad:type() == "Quad" or type(quad) == "number" then
    return love.graphics.draw(drawable, quad, (x or 0)*PPU, (y or 0)*PPU, r, (sx or 1)*PPU, (sy or 1)*PPU, ox, oy, kx, ky)
  end
  -- maybe a transform? in any case, pass the original arguments
  return love.graphics.draw(drawable, quad, x, y, r, sx, sy, ox, oy, kx, ky)
end
Another option is to apply the scale manually when drawing your entities, e.g.

Code: Select all

function Player:draw(x, y)
  love.graphics.draw(self.image[self.animState], x*PPU, y*PPU, 0, PPU, PPU)
end
Both methods have their problems, of course.

Another option is to buy a smaller monitor - mine is 1280x1024, for example :)

And of course there's the option of using something like Push, but I'm not sure how well it works for downscaling instead of upscaling.
User avatar
Xii
Party member
Posts: 137
Joined: Thu Aug 13, 2020 9:09 pm
Contact:

Re: 4K support, easy way to check monitor resolution (and physics)

Post by Xii »

Don't model your game world in pixels.
How you should model your game world depends on the type of game.

Let's say you're making an arena shooter. The arena is square. I'd measure coordinates as fractions of arena size. So x=0.0 is left edge of arena, x=1.0 is right edge. It's pretty easy to draw the arena to any resolution.

In a larger world, I'd use tile size as the unit. You'd have to calculate the size of a tile in pixels based on the current resolution, and how many sprites you want to fit on screen. As a bonus, you get zooming for free.
User avatar
darkfrei
Party member
Posts: 1169
Joined: Sat Feb 08, 2020 11:09 pm

Re: 4K support, easy way to check monitor resolution (and physics)

Post by darkfrei »

Xii wrote: Sun Jul 18, 2021 2:03 am In a larger world, I'd use tile size as the unit. You'd have to calculate the size of a tile in pixels based on the current resolution, and how many sprites you want to fit on screen. As a bonus, you get zooming for free.
It was my situation, I have tiles (128 pixels) and the agent, that is 1/8 of tile size. It the tile size twice bigger, then all speeds must be twice higher, right? But the jump speed have correlation to the gravity, it must be adjusted too.
:awesome: in Lua we Löve
:awesome: Platformer Guide
:awesome: freebies
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 52 guests