Theres something that goes very wrong in the drag path example I have here… It works fine when I start a path from the ball and release my mouse on the goal… If I release my mouse any where else on the screen and not on the word goal it gives me a whole bunch of errors. Does any one know way to tell the program to not draw a line if the mouse has not been released on the goal? Also Does any one know how to make the line show up after you have made a complete path from the ball to goal? That way the player knows that you can only draw a path if it has been connected to the word goal… Martian Controls shows this beautifully… I’m trying to master it but having some trouble… 
[lua]local maxPoints = 2
local lineThickness = 5
local endPoints = {}
local path = {}
local i =1
local traced = 1
local animate
local posCount = 1
local messageTween
–create a circle ball
local ball = display.newCircle( 150, 150, 15 )
local function drawLine(event)
if event.phase == “began” then
for i=1, traced, 1 do
table.remove (path ,i)
end
idx = 1
traced = 1
elseif event.phase == “moved” then
table.insert(endPoints, 1, {x = event.x, y = event.y, line= nil})
path[i] = {}
path[i].x = event.x
path[i].y = event.y
i = i + 1
if(#endPoints > maxPoints) then
table.remove(endPoints)
end
for i,v in ipairs(endPoints) do
local line = display.newLine(v.x, v.y, event.x, event.y)
line:setColor( 255, 255, 255, 255 )
line.width = lineThickness
path[traced].line = line
end
traced = traced + 1
elseif(event.phase == “ended”) then
while(#endPoints > 0) do
table.remove(endPoints)
path.isVisible = true
end
end
end
Runtime:addEventListener(“touch”, drawLine)
–moving the object – this is where animation takes place
local function moveObject(event)
if posCount < traced then
ball.x = path[posCount].x
ball.y = path[posCount].y
if path[posCount].line then
path[posCount].line.isVisible = false
path[posCount].line:removeSelf()
path[posCount].line = nil
end
posCount = posCount + 1
–path.isVisible = false
else
if animate then
timer.cancel(animate)
end
end
end
function anim()
animate = timer.performWithDelay( 10, moveObject, traced )
end
– to move ball when we click the animate text
local function move(event)
if(event.phase == “ended”) then
posCount = 1
transition.to(ball, { time = 500, x= path[1].x, y =path[1].y, onComplete= anim})
end
return true
end
–create a text which when clicked will animate the object
local text = display.newText( “Goal!”, 100, 50, nil, 40 )
text.x = 100; text.y = 425
text:addEventListener(“touch”, move)[/lua]
THANKS! [import]uid: 51459 topic_id: 15323 reply_id: 315323[/import]
[import]uid: 51459 topic_id: 15323 reply_id: 64881[/import]