Page 1 of 2
Find top, bottom, left and right side of the window?
Posted: Mon Dec 06, 2021 3:31 pm
by RealJace
Hello, so I am using Windfield library and wanted to make collisions for top, bottom, left and right side of the window so player doesn't go out of the window, and of course I need position for this, but I don't know how to do this, so how can I?
Re: Find top, bottom, left and right side of the window?
Posted: Mon Dec 06, 2021 5:51 pm
by grump
Left, top is 0, 0 and right, bottom is love.graphics.getWidth() - 1, love.graphics.getHeight() - 1
Re: Find top, bottom, left and right side of the window?
Posted: Tue Dec 07, 2021 12:13 am
by Xii
Making the physics and collisions of your game world depend on the window size is a bad idea. Window size can change in ways you might not expect, even if you set them to specific values.
Re: Find top, bottom, left and right side of the window?
Posted: Tue Dec 07, 2021 2:34 pm
by RealJace
Well my game is fullscreen sooo yeah.
Re: Find top, bottom, left and right side of the window?
Posted: Tue Dec 07, 2021 7:31 pm
by Xii
As I said, that won't work as you expect it to. People have different size screens. They can change resolution while your game is running. They can manually override fullscreen settings in graphics card configuration. There are many things which simply break your expectation here.
You should instead figure out how to render your game to a window of any size.
Re: Find top, bottom, left and right side of the window?
Posted: Tue Dec 07, 2021 9:31 pm
by pauljessup
Wow, man. You're just itching for a fight, aren't you?
Re: Find top, bottom, left and right side of the window?
Posted: Tue Dec 07, 2021 10:30 pm
by pgimeno
pauljessup wrote: ↑Tue Dec 07, 2021 9:31 pm
Wow, man. You're just itching for a fight, aren't you?
Usually people have a thicker skin than you seem to have or think they have. Xii is giving valid criticisms.
Re: Find top, bottom, left and right side of the window?
Posted: Tue Dec 14, 2021 2:02 am
by Jasoco
It's true. Windows can be resized. It's best if you choose a specific playfield size and learn how to render to a specific fixed size and scale that to fit the window. Personally I render my gameplay to a canvas of a specific dimension. Usually for me it's like 320x180 as I like retro low pixel games and it's a 16:9 size. Or I render to 1920x1080 if I'm doing something higher resolution. Basically always 16:9 for me.
Then you'd use some math to scale and move the rendered canvas to fit center in the window. Just always render the game itself to that canvas and display that canvas. Then people can resize the window all they want and not break things. I think there's some libraries out there to help with screen displaying.
Re: Find top, bottom, left and right side of the window?
Posted: Tue Dec 14, 2021 8:10 am
by darkfrei
grump wrote: ↑Mon Dec 06, 2021 5:51 pm
Left, top is 0, 0 and right, bottom is love.graphics.getWidth() - 1, love.graphics.getHeight() - 1
0.5, 0.5 and love.graphics.getWidth() - 0.5, love.graphics.getHeight() - 0.5,
But you can have 0 to width and 0 to height arrays for them.
Re: Find top, bottom, left and right side of the window?
Posted: Tue Dec 14, 2021 8:52 am
by grump
darkfrei wrote: ↑Tue Dec 14, 2021 8:10 am
0.5, 0.5 and love.graphics.getWidth() - 0.5, love.graphics.getHeight() - 0.5,
No. I think you're confusing different coordinate systems.
But you can have 0 to width and 0 to height arrays for them.
What do you mean, arrays for "them"? What is "them", pixels? And why would those arrays be larger than the window?