Page 1 of 1

[SOLVED] Refresh canvas?

Posted: Tue Sep 21, 2021 2:52 pm
by runs
I want to refresh a canvas. My code is:

Code: Select all

local function compose_canvas(x, y)
    --love.graphics.clear()
    love.graphics.setCanvas(canvas)
    love.graphics.setColor(0.8, 0.9, 0.4)
    love.graphics.rectangle("fill", x, y, 100, 100)
    love.graphics.setCanvas()
end

function love.load()
    canvas = love.graphics.newCanvas()
    compose_canvas(0, 0)
end

function love.draw()
    love.graphics.draw(canvas, 200, 100, 0, 0.5, 0.5)
end
The problem I have is that calling the compose_canvas function with other parameters, still remains the original one, and does not changes.

I tried with love.graphics.clear() but then the first canvas is created but in the second call dissapears.

Any idea?

Re: Refresh canvas?

Posted: Tue Sep 21, 2021 3:36 pm
by veethree
If i'm understanding you right, You just need to add love.graphics.clear() right below love.graphics.setCanvas(canvas)

Code: Select all

local function compose_canvas(x, y)
    --love.graphics.clear()
    love.graphics.setCanvas(canvas)
    love.graphics.clear()
    love.graphics.setColor(0.8, 0.9, 0.4)
    love.graphics.rectangle("fill", x, y, 100, 100)
    love.graphics.setCanvas()
end

function love.load()
    canvas = love.graphics.newCanvas()
    compose_canvas(0, 0)
end

function love.draw()
    love.graphics.draw(canvas, 200, 100, 0, 0.5, 0.5)
end

Re: Refresh canvas?

Posted: Tue Sep 21, 2021 9:39 pm
by runs
veethree wrote: Tue Sep 21, 2021 3:36 pm If i'm understanding you right, You just need to add love.graphics.clear() right below love.graphics.setCanvas(canvas)

Code: Select all

local function compose_canvas(x, y)
    --love.graphics.clear()
    love.graphics.setCanvas(canvas)
    love.graphics.clear()
    love.graphics.setColor(0.8, 0.9, 0.4)
    love.graphics.rectangle("fill", x, y, 100, 100)
    love.graphics.setCanvas()
end

function love.load()
    canvas = love.graphics.newCanvas()
    compose_canvas(0, 0)
end

function love.draw()
    love.graphics.draw(canvas, 200, 100, 0, 0.5, 0.5)
end
I tried, but simply the canvas dissapears, it does not redraw.

Re: Refresh canvas?

Posted: Tue Sep 21, 2021 10:05 pm
by veethree
Is this your whole code? Because this works fine for me.

Re: Refresh canvas?

Posted: Wed Sep 22, 2021 8:11 pm
by runs
Finally I've solved with love.graphics.reset( ) instead of clear() cos a previous scale setting, the canvas did not dissapear but was giant.

Thanx for your support.