Yeah, I know that. But i tried to make physics another way: i made little balls, which are in the line and added physics body to balls. So "line" has physics, but i had little problems with it. If i change line, balls in old line stays in old place and i couldnt remove them. I just got some error.
Well, where are you doing a:removeSelf() ? ;-)
Likely you need to be creating a table of the balls as you add them so you can then loop through that table and remove each ball.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
| lineBalls = {}
local function drawBezierSegment(granularity,r,g,b)
if line then
line:removeSelf()
end
line = display.newLine(bezierSegment[1].x,bezierSegment[1].y,bezierSegment[2].x,bezierSegment[2].y);
for i = 3, granularity, 1 do
line:append( bezierSegment[i].x,bezierSegment[i].y);
a = display.newCircle(bezierSegment[i].x,bezierSegment[i].y ,4)
physics.addBody( a,"static", {bounce = 0.0, friction = 0,radius=4})
lineBalls[#lineBalls+1] = a;
end
line:setColor(r,g,b);
line.width=2;
end
local function clearBalls (tableOfBalls)
local k,v
for k,v in pairs (tableOfBalls) do
if (v and v.removeSelf) then
v:removeSelf()
end
end
end |
Thanks for help, but clearballs() function didnt work for me. When i call it, i get error: "bad argument #1 to 'pairs' table expected, got nil"
Could you help little bit?
PS: you need to be creative, to create cool games :P
Never mind. I figured this out little bit different way. Now it is working perfectly.