When I draw a one pixel line, it splits into to two?

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.
User avatar
TechnoCat
Inner party member
Posts: 1611
Joined: Thu Jul 30, 2009 12:31 am
Location: Denver, CO
Contact:

Re: When I draw a one pixel line, it splits into to two?

Post by TechnoCat »

lines look good to me too.
User avatar
Jasoco
Inner party member
Posts: 3725
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: When I draw a one pixel line, it splits into to two?

Post by Jasoco »

Zac. Did you ever try posting your code here so we can see how you are doing it? It would help us figure out what you're doing wrong.
User avatar
zac352
Party member
Posts: 496
Joined: Sat Aug 28, 2010 8:13 pm
Location: In your head.
Contact:

Re: When I draw a one pixel line, it splits into to two?

Post by zac352 »

Jasoco wrote:Zac. Did you ever try posting your code here so we can see how you are doing it? It would help us figure out what you're doing wrong.

Code: Select all

if healthbar and v.alive then --dead cells don't need health bars anymore.
                local x1,y1=math.floor(v.x-8),math.floor(v.y-8)
                local x2,x3=math.floor(v.x+8),math.floor(v.x+(v.food/100)*16-8)
                love.graphics.setLineWidth(1)
                love.graphics.setLineStyle("rough")
                love.graphics.setColor(0,0,0)
                love.graphics.line(x3,y1,x2,y1)
                love.graphics.setColor(0,255,0)
                love.graphics.line(x1,y1,x3,y1)
            end
Hello, I am not dead.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: When I draw a one pixel line, it splits into to two?

Post by Robin »

Could you also post a screenshot that displays the problem? Because it seems no-one else can. ;)
Help us help you: attach a .love.
User avatar
Jasoco
Inner party member
Posts: 3725
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: When I draw a one pixel line, it splits into to two?

Post by Jasoco »

Code: Select all

love.graphics.line(x3+.5,y1+.5,x2,y1)
love.graphics.line(x1+.5,y1+.5,x3,y1)
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: When I draw a one pixel line, it splits into to two?

Post by Robin »

Jasoco wrote:

Code: Select all

love.graphics.line(x3+.5,y1+.5,x2,y1)
love.graphics.line(x1+.5,y1+.5,x3,y1)
Doesn't that make the lines slightly askew?
Help us help you: attach a .love.
User avatar
zac352
Party member
Posts: 496
Joined: Sat Aug 28, 2010 8:13 pm
Location: In your head.
Contact:

Re: When I draw a one pixel line, it splits into to two?

Post by zac352 »

Jasoco wrote:

Code: Select all

love.graphics.line(x3+.5,y1+.5,x2,y1)
love.graphics.line(x1+.5,y1+.5,x3,y1)
Will you please get out of your alternate reality where things like that work? When I tried that, it just made two fuzzy lines, instead of two sharp ones.
Hello, I am not dead.
User avatar
Jasoco
Inner party member
Posts: 3725
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: When I draw a one pixel line, it splits into to two?

Post by Jasoco »

Sorry. Forgot to add .5 to the other two values. If you add .5 to all of those values the line will be solid instead of split. Try it!

--REMOVED SEE BELOW!!!!

Robin, you should have caught that.

Also, Zac. That was rude. Go to your room.


Edit: Here's a much better example...

Code: Select all

love.graphics.setBackgroundColor(255,255,255)

love.graphics.setColor(0,0,0)

for i=0,9 do
    love.graphics.setLineWidth(i+1)
    love.graphics.line(20,20+(i*20), 300,20+(i*20))
end

for i=0,9 do
    love.graphics.setLineWidth(i+1)
    love.graphics.line(320,20+(i*20)+.5, 600,20+(i*20)+.5)
end

for i=0,9 do
    love.graphics.setLineWidth(i+1)
    if ((i+1)/2) ~= math.floor((i+1)/2) then  offset = .5 else offset = 0 end
    love.graphics.line(170,270+(i*20)+offset, 450,270+(i*20)+offset)
end

love.graphics.print("Without .5 offset", 20, 210)
love.graphics.print("With .5 offset", 320, 210)
love.graphics.print(".5 offset only on odd numbers", 170, 460)
Image

The first example doesn't add .5. Even numbered thicknesses will line up solidly. The second shows the opposite. Odd numbers show up right. The third alternates the offset to only be on odd numbers but not on even ones so it gives perfect solid lines right on the pixel.

Also think of it this way. If the line is horizontal, add to the Y. If it's vertical, add to the X. Decide which is best if it's diagonal. Also, for rectangles only add to the X and Y. Not the W and H.
User avatar
zac352
Party member
Posts: 496
Joined: Sat Aug 28, 2010 8:13 pm
Location: In your head.
Contact:

Re: When I draw a one pixel line, it splits into to two?

Post by zac352 »

That's really odd.
Hello, I am not dead.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: When I draw a one pixel line, it splits into to two?

Post by Robin »

Jasoco wrote:Robin, you should have caught that.
But I did... I told you, man. It would make the lines slightly askew.

Anyway, that's odd. Some people seem to need that, others don't. What versions of LÖVE are you all running? (For me it's the most recent build of 0.7.0.)
Help us help you: attach a .love.
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 6 guests