Line drawing dashed line

Hi Folks,

I’am pretty busy at the moment on developing a APP of the month :wink: and have a lot of stuff working so far.

Only thing i wan’t to implement is the following, now it works on single touches.

I need the user to draw a line from one object, and after that the object follows the drawn path. Not so hard, there are some samples and even a full project with examples, cheers and thanks for that.

The drawing go’s oke, but the only issue i’am fighting is the following:

When the user draws a line, i like to have a dashed line, like in flight control.

Example


But then also curved offcourse :slight_smile:

Could anyone probably help me on this one.

Cheers,
Jespar
[import]uid: 2734 topic_id: 8237 reply_id: 308237[/import]

Hi.

I modified a little bit the line drawing code from gtatarkin.

The code didn’t draw lines with the same length. Perhaps it helps to find a good solution.

[lua]-- original source code: Gesture recognition library for Corona SDK
http://developer.anscamobile.com/code/gesture-recognition-library-corona-sdk

– modified 110324 by sidasa
local moved = 0

local pointsTable = {}
local line
local function drawLine ()

if line then
line:removeSelf()
end

local numPoints = #pointsTable
local nl = {}
local j, p

local linewidth = 5

nl[1] = pointsTable[1]

j = 2
p = 1

for i = 2, numPoints, 1 do
nl[j] = pointsTable[i]
j = j+1
p = i
end

if ( p < numPoints -1 ) then
nl[j] = pointsTable[numPoints-1]
end

if #nl > 2 then
line = display.newLine(nl[1].x,nl[1].y,nl[2].x,nl[2].y)
line.width = linewidth
line:setColor(0,0,0)

for i = 3, #nl, 1 do
– draw next “step”
if #nl > i then
line = display.newLine(nl[i].x,nl[i].y,nl[i+1].x,nl[i+1].y)
else
line:append( nl[i].x,nl[i].y);
end
line.width = linewidth

– change color every “step”
if i%2 == 0 then
line:setColor(0,0,0)
else
line:setColor(255,255,255)
end

end
end
end

local function Update(event)
if “began” == event.phase then
pointsTable = nil
pointsTable = {}
local pt = {}
pt.x = event.x
pt.y = event.y
table.insert(pointsTable,pt)

elseif “moved” == event.phase then

local pt = {}
pt.x = event.x
pt.y = event.y
table.insert(pointsTable,pt)
moved = 1 –

elseif “ended” == event.phase or “cancelled” == event.phase then
if( moved == 1 ) then
drawLine ()
moved = 0
end
end
end

Runtime:addEventListener( “touch”, Update )[/lua] [import]uid: 42078 topic_id: 8237 reply_id: 29407[/import]

Thanks sidasa,

I will check it out if it will be usable and fast enough :wink:

Cheers,
Jespar
[import]uid: 2734 topic_id: 8237 reply_id: 29445[/import]

Hey guys:

I am new to Lua and Corona SDK. I was wondering how would I modify the above code so that it does solid lines instead of dashes? Also, how can I have a object9(s) following the path of the draw line(s).

Thank you so much!

Willy J.
[import]uid: 66859 topic_id: 8237 reply_id: 40076[/import]

Actually I figured that out!..

But, I have another question though. How can I get it to paint as I touch across the screen?

Thanks,

Willy J.
[import]uid: 66859 topic_id: 8237 reply_id: 40087[/import]

Okay, I figured this one out as well!

Willy J.
[import]uid: 66859 topic_id: 8237 reply_id: 40142[/import]