[SOLVED] Refresh canvas?

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
runs
Prole
Posts: 3
Joined: Tue Sep 21, 2021 2:44 pm

[SOLVED] Refresh canvas?

Post 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?
Last edited by runs on Wed Sep 22, 2021 8:11 pm, edited 1 time in total.
User avatar
veethree
Inner party member
Posts: 877
Joined: Sat Dec 10, 2011 7:18 pm

Re: Refresh canvas?

Post 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
runs
Prole
Posts: 3
Joined: Tue Sep 21, 2021 2:44 pm

Re: Refresh canvas?

Post 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.
User avatar
veethree
Inner party member
Posts: 877
Joined: Sat Dec 10, 2011 7:18 pm

Re: Refresh canvas?

Post by veethree »

Is this your whole code? Because this works fine for me.
runs
Prole
Posts: 3
Joined: Tue Sep 21, 2021 2:44 pm

Re: Refresh canvas?

Post 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.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest