Page 1 of 1

variables updated but not in love.graphics.rectangle

Posted: Fri Aug 05, 2022 8:37 am
by FranckEinstein
I would like to stop the progression of the rectangle when it approach the border. My var have a good value but not the rectangle in the screen

Code: Select all

function love.load()
    x, y, w, h = 20, 20, 60, 20
    width, height = love.window.getMode( )
end

function love.update(dt)
    if w < width-x then
        w = w + 1
    end
    if h < height-y then
        h = h + 1
    end
end

function love.draw()
    love.graphics.setColor(0, 0.4, 0.4)
    love.graphics.rectangle("fill", x, y, w, h)
    print(w,h)
end

Re: variables updated but not in love.graphics.rectangle

Posted: Mon Aug 08, 2022 5:31 pm
by milon
I does stop at the edge though, with no visible gap. If you want a black buffer around the rectangle, modify love.update to something like this:

Code: Select all

function love.update(dt)
    if w < width-x*2 then
        w = w + 1
    end
    if h < height-y*2 then
        h = h + 1
    end
end

Re: variables updated but not in love.graphics.rectangle

Posted: Mon Aug 08, 2022 5:44 pm
by FranckEinstein
Oh my God I'm so ashamed. Thanks a lot

Re: variables updated but not in love.graphics.rectangle

Posted: Mon Aug 08, 2022 5:48 pm
by milon
No worries! And you're welcome. I've had plenty of those moments myself - we all have! :)