love.graphics.scale() and screen positions

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.
Post Reply
User avatar
Gallefray
Prole
Posts: 10
Joined: Tue Oct 16, 2012 8:11 pm

love.graphics.scale() and screen positions

Post by Gallefray »

Hullo there!

I've looked around on the forums using the search function, to no avail...

My question is, how do I find the middle of the screen after applying love.graphics.scale?
I would have thought that you can just apply the values that you've used in love.graphics.scale() to the screens X and Y positions in some way or other...

Example:

Code: Select all

function love.load()
    screenHeight = love.graphics.getScreenHeight()
    screenWidth = love.graphics.getScreenWidth()
    scale = 0.3

    -- something LIKE this:
    middleScreenHeight = screenHeight/2 * scale
    middleScreenWidth = screenWidth/2 * scale

end

function love.draw()
    love.graphics.scale(scale, scale)
    love.graphics.setColor(255, 0, 0, 255)
    -- Draws the rectangle to the center of the screen
    love.graphics.rectangle(middleScreenHeight, middleScreenWidth, 32, 32)
end
Please help me, love2d forums, you're my only hope! (apart from stack overflow)
My name is Aster, but this forum does not allow people to change their username. I have not participated in development communities since around 2015-ish. More information about me is available here.
Santos
Party member
Posts: 384
Joined: Sat Oct 22, 2011 7:37 am

Re: love.graphics.scale() and screen positions

Post by Santos »

I think multiplying half the screen width and height by 1/scale should work.

Code: Select all

function love.load()
    screenHeight = love.graphics.getHeight()
    screenWidth = love.graphics.getWidth()
    scale = 0.3

    middleScreenHeight = screenHeight/2 * 1/scale
    middleScreenWidth = screenWidth/2 * 1/scale
end

function love.draw()
    love.graphics.scale(scale, scale)
    love.graphics.setColor(255, 0, 0)
    love.graphics.circle('fill', middleScreenWidth, middleScreenHeight, 32)
end
User avatar
Gallefray
Prole
Posts: 10
Joined: Tue Oct 16, 2012 8:11 pm

Re: love.graphics.scale() and screen positions

Post by Gallefray »

Santos wrote:I think multiplying half the screen width and height by 1/scale should work.

Code: Select all

    middleScreenHeight = screenHeight/2 * 1/scale
    middleScreenWidth = screenWidth/2 * 1/scale
It works like a charm! Thank you! If ĸarma was still on this forum, you would get a +1 :awesome:

Nyaa!
My name is Aster, but this forum does not allow people to change their username. I have not participated in development communities since around 2015-ish. More information about me is available here.
User avatar
xXxMoNkEyMaNxXx
Party member
Posts: 206
Joined: Thu Jan 10, 2013 6:16 am
Location: Canada

Re: love.graphics.scale() and screen positions

Post by xXxMoNkEyMaNxXx »

Multiplying by the reciprocal is a waste of time, just do the division in the first place.
User avatar
Gallefray
Prole
Posts: 10
Joined: Tue Oct 16, 2012 8:11 pm

Re: love.graphics.scale() and screen positions

Post by Gallefray »

xXxMoNkEyMaNxXx wrote:Multiplying by the reciprocal is a waste of time, just do the division in the first place.
example?
My name is Aster, but this forum does not allow people to change their username. I have not participated in development communities since around 2015-ish. More information about me is available here.
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: love.graphics.scale() and screen positions

Post by Nixola »

middleScreenHeight = screenHeight/2/scale
middleScreenWidth = screenWidth/2/scale
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
Post Reply

Who is online

Users browsing this forum: Roland Chastain and 199 guests