When I draw a one pixel line, it splits into to two?
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- 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?
lines look good to me too.
- 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?
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.
Re: When I draw a one pixel line, it splits into to two?
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.
- 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?
Could you also post a screenshot that displays the problem? Because it seems no-one else can.
Help us help you: attach a .love.
- 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?
Code: Select all
love.graphics.line(x3+.5,y1+.5,x2,y1)
love.graphics.line(x1+.5,y1+.5,x3,y1)
- 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?
Doesn't that make the lines slightly askew?Jasoco wrote:Code: Select all
love.graphics.line(x3+.5,y1+.5,x2,y1) love.graphics.line(x1+.5,y1+.5,x3,y1)
Help us help you: attach a .love.
Re: When I draw a one pixel line, it splits into to two?
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.Jasoco wrote:Code: Select all
love.graphics.line(x3+.5,y1+.5,x2,y1) love.graphics.line(x1+.5,y1+.5,x3,y1)
Hello, I am not dead.
- 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?
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...
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.
--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)
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.
- 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?
But I did... I told you, man. It would make the lines slightly askew.Jasoco wrote:Robin, you should have caught that.
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.
Who is online
Users browsing this forum: Google [Bot] and 6 guests