Will someone share with me the best way to allow the user to swipe to draw a line that will have physics so that moving balls will bounce off of it.
The user should be able to draw lines all over the place, move them, change their angle and be able to remove lines with a double click or some other way.
Similar to what is in the game Soundrop.
Best method? I looked through the forum but didn't find what I needed (or missed it).
Thanks,
Al
This will give you somewhere to start; http://developer.anscamobile.com/code/draw-line
Peach :)
Hey,
I would advise you to use this instead: http://developer.anscamobile.com/code/gerald-anderson
It is a more improved version.
Peach and Michael,
Thank you for your responses. They were both a big help.
Not sure what I have to do to keep "straight" lines. I.e. I want a straight line between the touch begin and the touch end. Then I want the lines to be able to be individually moved, rotated and/or deleted.
Any ideas on how to do that?
Thanks.
Al
Your welcome.
I would try to modify the physics, from what we have provided you already. But, this should give you some start.
Straight Lines:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
| function drawLine( event )
if (event.phase == "began") then
if line == nil then
else
line:removeSelf()
end
end
if(event.phase == "ended") then
line = display.newLine(event.xStart, event.yStart, event.x, event.y)
line:setColor(255,0,0)
line.width = 15
physics.addBody( line, "static", { density=0.3, friction=0.6, bounce=0.8} )
end
end
Runtime:addEventListener("touch", drawLine) |