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?
Making a Dotted/Dashed Line
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Re: Making a Dotted/Dashed Line
You can create your own line drawing function. It would typically look something like this:
Now think of how you could make a strippled line. Thinking it up yourself always helps learning!
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
Re: Making a Dotted/Dashed Line
Based on diagonal marching, between two points is distance as longest coordinate difference:
For dash line check
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
Code: Select all
if iStep%4 < 2 then -- add point
Re: Making a Dotted/Dashed Line
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!
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!
Any code samples/ideas by me should be considered Public Domain (no attribution needed) license unless otherwise stated.
Re: Making a Dotted/Dashed Line
Also noting love.graphic.point doesn't work any more.
love.graphic.points can be used exactly the same way.
love.graphic.points can be used exactly the same way.
Last project:
https://togfox.itch.io/hwarang
A card game that brings sword fighting to life.
Current project:
Idle gridiron. Set team orders then idle and watch: https://togfox.itch.io/idle-gridiron
https://togfox.itch.io/hwarang
A card game that brings sword fighting to life.
Current project:
Idle gridiron. Set team orders then idle and watch: https://togfox.itch.io/idle-gridiron
Who is online
Users browsing this forum: Bing [Bot], plexity and 3 guests