Drawing game

So I’m trying to figure out how to do a drawing game, where you can draw pictures. I have an event listener on touch leading to a function with this in it: print(event.x,event.y).

So basically if I drag my mouse around the simulator, I get loaded up with “100 100, 200 200, 300 300”, etc. How do I make that into a line?

Should I do like display.newCircle( 0, event.x, event.y, 1 ) ? [import]uid: 38631 topic_id: 7287 reply_id: 307287[/import]

Corona has a native polyline display object. [import]uid: 3953 topic_id: 7287 reply_id: 26077[/import]

Do you know how to do this? I did a search for polyline display object and I came up with nothing.

Thanks. [import]uid: 38631 topic_id: 7287 reply_id: 26209[/import]

(whilst dragging) store the points in an array, redraw the line from those points each frame [import]uid: 6645 topic_id: 7287 reply_id: 26243[/import]

Here is the info you want [import]uid: 3953 topic_id: 7287 reply_id: 26390[/import]

This will help to draw lines :

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=4
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”, { bounce = -1, 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)

ball.myName = “ball”
outline.myName = “outline”

ball:addEventListener(“collision”, ball)

function ball:collision (event)
if event.other.myName == “outline” then
ball:applyLinearImpulse(0,-0.2, ball.x, ball.y)

end
end
[import]uid: 23689 topic_id: 7287 reply_id: 42940[/import]

sorry,

this is the code:

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=4
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”, { bounce = -1, 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)
[import]uid: 23689 topic_id: 7287 reply_id: 42941[/import]