variables updated but not in love.graphics.rectangle

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
FranckEinstein
Prole
Posts: 2
Joined: Fri Aug 05, 2022 8:17 am

variables updated but not in love.graphics.rectangle

Post 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
milon
Party member
Posts: 401
Joined: Thu Jan 18, 2018 9:14 pm

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

Post 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
FranckEinstein
Prole
Posts: 2
Joined: Fri Aug 05, 2022 8:17 am

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

Post by FranckEinstein »

Oh my God I'm so ashamed. Thanks a lot
milon
Party member
Posts: 401
Joined: Thu Jan 18, 2018 9:14 pm

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

Post by milon »

No worries! And you're welcome. I've had plenty of those moments myself - we all have! :)
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 9 guests