[SOLVED] setColor usage

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
Styper
Prole
Posts: 6
Joined: Sun Jul 29, 2018 11:53 am

[SOLVED] setColor usage

Post 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 6061 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
Last edited by Styper on Mon Jul 30, 2018 12:43 am, edited 1 time in total.
User avatar
D0NM
Party member
Posts: 250
Joined: Mon Feb 08, 2016 10:35 am
Location: Zabuyaki
Contact:

Re: setColor usage

Post 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 ^__^
Our LÖVE Gamedev blog Zabuyaki (an open source retro beat 'em up game). Twitter: @Zabuyaki.
:joker: LÖVE & Lua Video Lessons in Russian / Видео уроки по LÖVE и Lua :joker:
Styper
Prole
Posts: 6
Joined: Sun Jul 29, 2018 11:53 am

Re: setColor usage

Post 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?
User avatar
pgimeno
Party member
Posts: 3551
Joined: Sun Oct 18, 2015 2:58 pm

Re: setColor usage

Post 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.
Styper
Prole
Posts: 6
Joined: Sun Jul 29, 2018 11:53 am

Re: setColor usage

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

Who is online

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