Hi,
I have been messing with joints, I used Carlos’ ball on a rope code as a reference.
Now my problem is, how the heck do I destroy the rope ?
I have tried many things, using pairs and ipairs but no joy whatsoever.
I am missing something simple I feel can anybody help and point me in the correct direction please.
[lua]
local physics = require (“physics”)
physics.start ()
physics.setGravity (0, 10)
local ceiling = display.newRect (0, 0, display.contentWidth, 1)
physics.addBody (ceiling, “static”, {bounce = 0.0, friction = 10})
local xCenter = 160
local hCeil = -5
local prevBody = ceiling
local w,h = 10,10
local halfW,halfH = 0.5*w,0.5*h
local x = xCenter
local y = hCeil - halfH
local yJoint = y - halfH
for i = 1, 20 do
y = y + h
yJoint = yJoint + h
local chainlinks = display.newImage(“rope.png” ,x-halfW, y-halfH)
physics.addBody( chainlinks, { density=15, friction=0.5, bounce = .2 })
local chainjoint = physics.newJoint( “pivot”, prevBody, chainlinks, xCenter, yJoint )
newBody = chainlinks
function removeLinks()
print(“removelinks called”) --CODE HERE TO REMOVE THE ROPE–
end
end
local key = display.newImage(“soccerball.png”, x,y -30)
physics.addBody( key, { density=2, friction=0.5, bounce=.2, radius=20 })
local joint = physics.newJoint( “pivot”, newBody, key, xCenter, y )
local function removeEverything()
display.remove(ceiling)
ceiling = nil
removeLinks()
display.remove(key)
key = nil
end
timer.performWithDelay(2000,removeEverything,1)
[/lua]