Problem with the line color

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
Kibita
Prole
Posts: 31
Joined: Tue Dec 29, 2015 7:46 pm

Problem with the line color

Post by Kibita »

Hello!

I'm trying to make an effect that "simulates" the stars in movement and I'm making them with the color white, but some lines are showing grey, as you can see in the image:

Image

And here's where I draw each line:

Code: Select all

function GameEffect:draw()
    for i=1, #self.rays do
        love.graphics.setColor(255, 255, 255)
        love.graphics.setLineWidth(1.5)
        love.graphics.line(self.rays[i].x, self.rays[i].y, self.rays[i].x + self.rays[i].lenght, self.rays[i].y)
        love.graphics.setLineWidth(self.defaultWidth)
    end
end
I used setLineWidth to see if this could help, but it didn't.

What causes it and how can I fix it? Thank you.
User avatar
pgimeno
Party member
Posts: 3673
Joined: Sun Oct 18, 2015 2:58 pm

Re: Problem with the line color

Post by pgimeno »

Can't reproduce:

Code: Select all

local GameEffect = {}

function love.load()
  love.window.setMode(430, 356)
  local gen = love.math.newRandomGenerator(4)
  GameEffect.rays = {}
  GameEffect.defaultWidth = 1
  for i = 1, 15 do
    GameEffect.rays[#GameEffect.rays + 1] = {
      lenght = 60;
      x = gen:random(370);
      y = gen:random(354);
    }
  end
end

function love.draw()
    love.graphics.clear(217, 207, 80)
    GameEffect:draw()
end

function GameEffect:draw()
    for i=1, #self.rays do
        love.graphics.setColor(255, 255, 255)
        love.graphics.setLineWidth(1.5)
        love.graphics.line(self.rays[i].x, self.rays[i].y, self.rays[i].x + self.rays[i].lenght, self.rays[i].y)
        love.graphics.setLineWidth(self.defaultWidth)
    end
end

function love.keypressed(k) if k == "escape" then love.event.quit() end end
Image

If you need further help, please post a .love file or at least a complete reproducible test case like the above.
User avatar
rmcode
Party member
Posts: 454
Joined: Tue Jul 15, 2014 12:04 pm
Location: Germany
Contact:

Re: Problem with the line color

Post by rmcode »

@Kibita: Is it possible you are drawing the lines at non-integer coordinates (10.393, 12.939 for example)? If so, try to math.floor the coordinates before drawing.
User avatar
pgimeno
Party member
Posts: 3673
Joined: Sun Oct 18, 2015 2:58 pm

Re: Problem with the line color

Post by pgimeno »

Modifying the coordinate generation above as follows, I still can't reproduce:

Code: Select all

      x = gen:random()*370;
      y = gen:random()*354;
Image
(the differences are subtle, but visible when zooming)
User avatar
Kibita
Prole
Posts: 31
Joined: Tue Dec 29, 2015 7:46 pm

Re: Problem with the line color

Post by Kibita »

Oh my God, I just used love.graphics.clear that pgimeno used and it worked!
User avatar
Pangit
Party member
Posts: 148
Joined: Thu Jun 16, 2016 9:20 am

Re: Problem with the line color

Post by Pangit »

This was what I got..
colour.png
colour.png (1.32 KiB) Viewed 4287 times
User avatar
slime
Solid Snayke
Posts: 3166
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: Problem with the line color

Post by slime »

love.graphics.clear is unnecessary in the default [wiki]love.run[/wiki], since LÖVE calls it directly before love.draw is called. You can use [wiki]love.graphics.setBackgroundColor[/wiki] to set the color it uses for that clear call.
User avatar
pgimeno
Party member
Posts: 3673
Joined: Sun Oct 18, 2015 2:58 pm

Re: Problem with the line color

Post by pgimeno »

Indeed, same result without love.graphics.clear as expected. For some reason I thought that setBackgroundColor had been removed.

Code: Select all

local GameEffect = {}

function love.load()
  love.window.setMode(430, 356)
  local gen = love.math.newRandomGenerator(4)
  GameEffect.rays = {}
  GameEffect.defaultWidth = 1
  for i = 1, 15 do
    GameEffect.rays[#GameEffect.rays + 1] = {
      lenght = 60;
      x = gen:random()*370;
      y = gen:random()*354;
    }
  end
  love.graphics.setBackgroundColor(217, 207, 80)
end

function love.draw()
    GameEffect:draw()
end

function GameEffect:draw()
    for i=1, #self.rays do
        love.graphics.setColor(255, 255, 255)
        love.graphics.setLineWidth(1.5)
        love.graphics.line(self.rays[i].x, self.rays[i].y, self.rays[i].x + self.rays[i].lenght, self.rays[i].y)
        love.graphics.setLineWidth(self.defaultWidth)
    end
end

function love.keypressed(k) if k == "escape" then love.event.quit() end end
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Semrush [Bot] and 5 guests