Page 1 of 1

[SOLVED] setColor usage

Posted: Sun Jul 29, 2018 12:17 pm
by Styper
Hello,

I'm new to LUA and Love2D and I'm getting this problem, I've tried searching for an answer already but no luck.

When I use graphics.setColor it's coloring my "background" image too.

Here's my code:

Code: Select all

function love.draw()
  love.graphics.scale(love.graphics.getWidth()/800, love.graphics.getHeight()/600)
  love.graphics.draw(background, 0, 0)
  
  love.graphics.setLineWidth(10)
  love.graphics.setLineStyle("smooth")
  
  love.graphics.setColor(255, 0, 0)
  love.graphics.line(200,50, 400,50, 500,300, 100,300, 200,50)
  
  love.graphics.setColor(0, 255, 0)
  love.graphics.line(250,50, 450,50, 550,300, 150,300, 250,50)

  love.graphics.setColor(0, 0, 255)
  love.graphics.line(350,50, 550,50, 650,300, 250,300, 350,50)
end
And here's the result:
Selection_148.png
Selection_148.png (481.46 KiB) Viewed 6313 times
How come the last color I apply (blue) gets applied to the whole screen? How can I prevent that?

On a side question, how come adding this line to love.draw() works but not love.resize(w, h)?

Code: Select all

love.graphics.scale(love.graphics.getWidth()/800, love.graphics.getHeight()/600)
Thanks in advance

Re: setColor usage

Posted: Sun Jul 29, 2018 1:11 pm
by D0NM
It wasn't applied to the whole screen. It just became the CURRENT colour in the end.
So, on the next iteration it is applied to love.graphics.draw(background, 0, 0)

Be sure to set WHITE colour before drawing your BG picture.

read manual ^__^

Re: setColor usage

Posted: Sun Jul 29, 2018 1:45 pm
by Styper
D0NM wrote: Sun Jul 29, 2018 1:11 pm It wasn't applied to the whole screen. It just became the CURRENT colour in the end.
So, on the next iteration it is applied to love.graphics.draw(background, 0, 0)

Be sure to set WHITE colour before drawing your BG picture.

read manual ^__^
Thank you very much, it worked.
Styper wrote: Sun Jul 29, 2018 12:17 pm On a side question, how come adding this line to love.draw() works but not love.resize(w, h)?

Code: Select all

love.graphics.scale(love.graphics.getWidth()/800, love.graphics.getHeight()/600)
Do you also know the answer to this question?

Re: setColor usage

Posted: Sun Jul 29, 2018 3:32 pm
by pgimeno
love.resize is not a function that you call. It's a callback that gets called when the window is resized (typically by using the window resizing handles that your window manager provides), to notify your code that the window size has changed.

If you mean that love.graphics.scale doesn't work when you use it in the love.resize event, that's because right before calling love.graphics.draw, the transform is reset.

Re: setColor usage

Posted: Sun Jul 29, 2018 7:01 pm
by Styper
pgimeno wrote: Sun Jul 29, 2018 3:32 pm If you mean that love.graphics.scale doesn't work when you use it in the love.resize event, that's because right before calling love.graphics.draw, the transform is reset.
Thank you, that settles it!