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
pgimeno
Party member
Posts: 3541
Joined: Sun Oct 18, 2015 2:58 pm

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

Post by pgimeno »

darkfrei wrote: Sun Jul 18, 2021 3:10 pm 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?
I must insist on this point. Not necessarily.

Imagine you're watching a video of someone jumping onto a crate. Now imagine that you see the same video, but with 2x zoom.

Now you can see this situation from two angles:

a) The crate in the original video is N pixels high, and in the zoomed video it is 2N pixels high. The number of pixels is doubled, therefore the jump in pixels/s must be twice the speed and the gravity must be adjusted to a new value in pixels/s².

Or:

b) The crate in the original video is N metres high, and same in the zoomed video. The speed of the jumping guy is in m/s and the gravity is in m/s², and they are the same in both videos. Each metre is PPU pixels, therefore the crate in the original video is N*PPU pixels high and in the zoomed video it is 2*N*PPU pixels high, but that doesn't change the speed or the gravity of the guy.

You seem to keep thinking in terms of (a); I'm suggesting you to look at it as in (b).
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 »

Your game world simulation shouldn't have "pixels" mentioned anywhere in it. love.update() shouldn't think about pixels at all.

Only in love.draw() should you calculate how to draw the game world in the current resolution. Like,

Code: Select all

sprite_width = screen_width / sprites_per_screen_width
So if your screen width is 1920 pixels and you want to fit say 12 sprites horizontally on screen, this gives you a sprite_width of 1920/12=160 pixels.

You want to do this calculation on the shorter axis of the screen. Think about how to deal with different aspect ratios. Myself I "pretend" the screen is a 1:1 square, then treat the leftover space as a special case.
Post Reply

Who is online

Users browsing this forum: No registered users and 23 guests