Why is my screen center this

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
RpxdYTX
Prole
Posts: 2
Joined: Fri Feb 14, 2025 3:01 pm

Why is my screen center this

Post by RpxdYTX »

I was doing my own camera transformations in löve, and i wanted the origin to be the center (instead of the corner) to better handle different aspect ratios.
My screen is 1480x720, and the offset vector needed to be (480, 216) to feel minimally centered. I got those values using a seemingly random equation to make sure that the y-axis stays the same, expanding over the x-axis if the screen ratio is not 16:9. I also confirmed that it is really the center of the screen by using

Code: Select all

love.graphics.line
Why is that the center of the screen and not just 740x360?
User avatar
BrotSagtMist
Party member
Posts: 680
Joined: Fri Aug 06, 2021 10:30 pm

Re: Why is my screen center this

Post by BrotSagtMist »

obey
RpxdYTX
Prole
Posts: 2
Joined: Fri Feb 14, 2025 3:01 pm

Re: Why is my screen center this

Post by RpxdYTX »

Oh, thanks.
In the docs for that function i found out what gives the actual width and height without the dpi scaling, being the functions getWidth / getHeight in love.graphics.
User avatar
zorg
Party member
Posts: 3477
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Why is my screen center this

Post by zorg »

You could also use the following function to make the center point (0,0) on the coordinate system you use:

love.graphics.translate(-love.graphics.getWidth()/2, -love.graphics.getHeight()/2)

Now, "normally", the above should account for DPI scaling (the functions that don't are getPixelWidth and getPixelHeight) but iirc windows has buggy DPI stuff and/or SDL has incomplete support for it, so you need to do some extra work to have it work correctly.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest