Clear a 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
User avatar
Miken1
Prole
Posts: 42
Joined: Tue Nov 05, 2013 8:35 am
Location: Sweden

Clear a canvas?

Post by Miken1 »

Hello!

I'm getting this weird constant drawing effect when I'm drawing something on a canvas.
Am I doing something wrong?

Code: Select all

function love.load()
  
  x, y = 0, 0
  width, height = 10, 10
  love.graphics.setBackgroundColor(80,80,80)

  canvas = love.graphics.newCanvas(200, 200)
  
end
function love.update()
  
  x, y = x + 0.1, y + 0.1

end
function love.draw()
  love.graphics.setCanvas(canvas)
  love.graphics.rectangle("fill", x, y, width, height)
  love.graphics.setCanvas()
  love.graphics.draw(canvas, 0, 0)

end
User avatar
Jasoco
Inner party member
Posts: 3727
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Clear a canvas?

Post by Jasoco »

After you setCanvas, immediately clear it before you start drawing anything.

love.graphics.clear(color)

Where color is the color to make it. Use 0,0,0,0 or 255,255,255,0 or any other color as long as zero is the fourth (alpha) number if you want it to be transparent. Or leave the alpha empty if you want it opaque.
User avatar
Miken1
Prole
Posts: 42
Joined: Tue Nov 05, 2013 8:35 am
Location: Sweden

Re: Clear a canvas?

Post by Miken1 »

Jasoco wrote:After you setCanvas, immediately clear it before you start drawing anything.

love.graphics.clear(color)

Where color is the color to make it. Use 0,0,0,0 or 255,255,255,0 or any other color as long as zero is the fourth (alpha) number if you want it to be transparent. Or leave the alpha empty if you want it opaque.
Oh....


Thanks alot!
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: Clear a canvas?

Post by Nixola »

Miken1 wrote:Thanks alot!
Alot is welcome.
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 2 guests