Canvas only visible for one frame after I click.

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
samurliko
Prole
Posts: 2
Joined: Sat Aug 01, 2015 3:10 pm

Canvas only visible for one frame after I click.

Post by samurliko »

I was experimenting with the canvas. In the test when you click a green dot is placed at your cursor position, but the green dots are only visible for a short time after you click.

This is my entire code:

Code: Select all

function love.load()
  dots = love.graphics.newCanvas(800, 600)
  
  love.mouse.setVisible(false)
end

function love.mousepressed(x, y, button)
  if button == "l" then
    love.graphics.setCanvas(dots)
    love.graphics.setColor(0, 255, 0, 255)
    love.graphics.circle("fill", x, y, 10, 16)
    love.graphics.setCanvas()
  end
end

function love.draw()
  love.graphics.setBlendMode('premultiplied')
  love.graphics.draw(dots)
  local x, y = love.mouse.getPosition()
  love.graphics.setColor(255, 0, 0)
  love.graphics.circle("fill", x, y, 20, 16)
end
User avatar
arampl
Party member
Posts: 248
Joined: Mon Oct 20, 2014 3:26 pm

Re: Canvas only visible for one frame after I click.

Post by arampl »

This issue becoming soooo common!

Just use love.graphics.setColor(255, 255, 255) before drawing canvas. It's all about colors multiplication.
User avatar
slime
Solid Snayke
Posts: 3162
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: Canvas only visible for one frame after I click.

Post by slime »

arampl wrote:This issue becoming soooo common!
Yeah, it's one of the problems with the love.graphics API model of setting global state for something that is usually only intended to affect the few lines directly below it.

Suggestions for how to improve the situation are welcome. :)
samurliko
Prole
Posts: 2
Joined: Sat Aug 01, 2015 3:10 pm

Re: Canvas only visible for one frame after I click.

Post by samurliko »

Thanks, I did that and it works now.
User avatar
arampl
Party member
Posts: 248
Joined: Mon Oct 20, 2014 3:26 pm

Re: Canvas only visible for one frame after I click.

Post by arampl »

slime wrote:Suggestions for how to improve the situation are welcome. :)
How about additional 'color' parameter in primitive drawing functions?
SDL_draw and SDL_gfx libraries uses this approach.
User avatar
zorg
Party member
Posts: 3465
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Canvas only visible for one frame after I click.

Post by zorg »

arampl wrote:
slime wrote:Suggestions for how to improve the situation are welcome. :)
How about additional 'color' parameter in primitive drawing functions?
SDL_draw and SDL_gfx libraries uses this approach.
And soon after, the need for a "blendmode" parameter comes, then another, then another... :3

And finally, we can all stop worrying
about lg.draw(drawable,x,y,z,r,sx,sy,ox,oy,color,blendmode,mesh,source,scissors,vbo,u,v) et. al.
affecting any state at all :D
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 1 guest