Page 1 of 1
Making a Dotted/Dashed Line
Posted: Wed Sep 12, 2012 9:33 am
by kexisse
I'm trying to draw a dotted/dashed line.
I just found
setLineStipple but it's removed in Löve 0.8.
Is there an alternative method?
Re: Making a Dotted/Dashed Line
Posted: Wed Sep 12, 2012 2:29 pm
by Anickyan
You can create your own line drawing function. It would typically look something like this:
Code: Select all
function drawLine(x1, y1, x2, y2)
love.graphics.setPointSize(1)
local x, y = x2 - x1, y2 - y1
local len = math.sqrt(x^2 + y^2)
local stepx, stepy = x / len, y / len
x = x1
y = y1
for i = 1, len do
love.graphics.point(x, y)
x = x + stepx
y = y + stepy
end
end
Now think of how you could make a strippled line. Thinking it up yourself always helps learning!
Re: Making a Dotted/Dashed Line
Posted: Fri Sep 01, 2023 10:53 am
by darkfrei
Based on diagonal marching, between two points is distance as longest coordinate difference:
Code: Select all
function getLinePoints(x1, y1, x2, y2)
local points = {}
local deltaX, deltaY = x2 - x1, y2 - y1
local len = math.max (math.abs(deltaX), math.abs(deltaY))
for iStep = 0, len do -- including first and last points
table.insert (points, x1 + deltaX * iStep/len)
table.insert (points, y1 + deltaY * iStep/len)
end
return points
end
For dash line check
Re: Making a Dotted/Dashed Line
Posted: Thu Sep 07, 2023 4:08 pm
by milon
Here's a pretty elegant method that still works!
viewtopic.php?t=83295
EDIT - Wow, just realized this is quite a necro! >_<
But it's amazing that a draw method from 7 years ago still works!
Re: Making a Dotted/Dashed Line
Posted: Sat Sep 09, 2023 3:06 am
by togFox
Also noting love.graphic.point doesn't work any more.
love.graphic.points can be used exactly the same way.