Draw Mode

Hello,

I am using this code to draw a line. When i add physics into the picture, then add the draw mode half of the line is square. How do i change this ? To make the the actual line a physic body, for a ball to roll down.

function drawLine( event )
if(event.phase == “ended”) then
line = display.newLine(event.xStart, event.yStart, event.x, event.y)
line:setColor(255,255,255)
line.width = 5

end
end
Runtime:addEventListener(“touch”, drawLine)

Thank you. [import]uid: 23689 topic_id: 10276 reply_id: 310276[/import]

even better

[lua]local physics = require “physics”
physics.start()
physics.setGravity(0,3)
staticMaterial = {friction=.2,bounce=.2}

----------------------------- create new Circle -------------------------------------

local circle = display.newCircle(100,0,20)
physics.addBody(circle, staticMaterial)

----------------------------- create new Ractangle -------------------------------------

local ractangle = display.newRect(60,100,900,40)
physics.addBody(ractangle, “static”, staticMaterial)
function ractangle:touch(event)
if event.phase == “ended” then
ractangle:removeSelf()
end
end
ractangle:addEventListener(“touch”,ractangle)

----------------------------- create new Line -------------------------------------
local i = 1
local tempLine
local ractgangle_hit = {}
local prevX , prevY
local function runTouch(event)
if(event.phase==“began”) then
if(tempLine==nil) then
tempLine=display.newLine(event.x, event.y, event.x, event.y)
tempLine:setColor(255,255,255,255)
tempLine.width=5
prevX = event.x
prevY = event.y
end
elseif(event.phase==“moved”) then
tempLine:append(event.x,event.y-2)
tempLine.width=tempLine.width+0.000001
ractgangle_hit[i] = display.newLine(prevX, prevY, event.x, event.y)
ractgangle_hit[i]:append(event.x,event.y)
ractgangle_hit[i].width=2
ractgangle_hit[i].alpha = 0

local Width = ractgangle_hit[i].width * 0.3
local Height = ractgangle_hit[i].height * 0.3
local lineShape = {-Width,-Height,Width,-Height,Width,Height,-Width,Height}

physics.addBody(ractgangle_hit[i], “static”, { density=0.3, friction=0.7, shape = lineShape})
prevX = event.x
prevY = event.y
i = i + 1
elseif(event.phase==“ended”) then
tempLine.parent.remove(tempLine)
tempLine=nil
end
end
Runtime:addEventListener(“touch”, runTouch)[/lua]

probably you need to optimize code i doubt it will not give good fps but good [import]uid: 12482 topic_id: 10276 reply_id: 37559[/import]

How does this work?
[import]uid: 23689 topic_id: 10276 reply_id: 37562[/import]

THANK YOU SOO MUCH! [import]uid: 23689 topic_id: 10276 reply_id: 37564[/import]

glad that worked

:slight_smile: [import]uid: 12482 topic_id: 10276 reply_id: 37566[/import]

Hey There:

How can you delete the line after drawing another line?

Thanks,

Willy J.
[import]uid: 66859 topic_id: 10276 reply_id: 45418[/import]