Find top, bottom, left and right side of the window?

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: 3551
Joined: Sun Oct 18, 2015 2:58 pm

Re: Find top, bottom, left and right side of the window?

Post by pgimeno »

Pixel centres are where darkfrei said. For lines, line rectangles and polygons, it's generally better to use those. For rectangles and images (and anything rectangular) it's best to use integral dimensions.

Technically the left border is indeed 0, 0 but the right border is love.graphics.getWidth(), love.graphics.getHeight(). For collisions, which is what the OP was about, you usually have a rectangle-rectangle collision, and if you use 0 and love.graphics.getWidth() - 1 as left and right limits for the X coordinate respectively, there will be a 1 pixel line margin on the right.
grump
Party member
Posts: 947
Joined: Sat Jul 22, 2017 7:43 pm

Re: Find top, bottom, left and right side of the window?

Post by grump »

This thread has everything: window coordinates, physics, a short essay on canvas scaling, pixel center coordinates, arrays (???), and where to render primitives.

To summarise the important information:

The left-top pixel in window coordinates is at 0, 0. The right-bottom pixel in window coordinates is at love.graphics.getWidth() - 1, love.graphics.getHeight() - 1.

The bounds encompassing the window area are 0, 0 (left, top) and love.graphics.getWidth(), love.graphics.getHeight() (right, bottom).
User avatar
darkfrei
Party member
Posts: 1183
Joined: Sat Feb 08, 2020 11:09 pm

Re: Find top, bottom, left and right side of the window?

Post by darkfrei »

grump wrote: Tue Dec 14, 2021 8:52 am
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?
If you draw the rectangle in "line", then it must be shifted at 0.5 pixel. The same for lines, as I know.

If you make a grid every 100 pixels in the window 800x600, then you can draw the lines at x=0, x=800, y=0, y=600 too.
:awesome: in Lua we Löve
:awesome: Platformer Guide
:awesome: freebies
grump
Party member
Posts: 947
Joined: Sat Jul 22, 2017 7:43 pm

Re: Find top, bottom, left and right side of the window?

Post by grump »

darkfrei wrote: Tue Dec 14, 2021 11:30 am If you draw the rectangle in "line", then it must be shifted at 0.5 pixel. The same for lines, as I know.

If you make a grid every 100 pixels in the window 800x600, then you can draw the lines at x=0, x=800, y=0, y=600 too.
Yeah, points, lines, and other primitives in 'line' mode. Those are the rasterizer rules, not the window coordinate rules. Window coordinates are integer. For example, a mouse cursor in the top-left corner of the window is at 0, 0. Not 0.5, 0.5.

I wouldn't count on your grid thing. Whether or not those lines are visible is a gamble and depends on GPU and drivers, and the selected line smoothing mode.

All of this is severely underdocumented in the wiki, and all examples are wrong.
Post Reply

Who is online

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