Page 1 of 1

love.graphics.scale() and screen positions

Posted: Sat Jan 26, 2013 11:40 pm
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)

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

Posted: Sun Jan 27, 2013 3:18 am
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

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

Posted: Sun Jan 27, 2013 11:02 am
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!

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

Posted: Sun Jan 27, 2013 11:09 am
by xXxMoNkEyMaNxXx
Multiplying by the reciprocal is a waste of time, just do the division in the first place.

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

Posted: Mon Jan 28, 2013 5:03 pm
by Gallefray
xXxMoNkEyMaNxXx wrote:Multiplying by the reciprocal is a waste of time, just do the division in the first place.
example?

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

Posted: Mon Jan 28, 2013 5:06 pm
by Nixola
middleScreenHeight = screenHeight/2/scale
middleScreenWidth = screenWidth/2/scale