Right I am making some progress but it isn’t looking very natural 
[lua]require ( “physics” )
physics.start()
physics.setGravity( 0, 9.6 )
local link = {}
physics.setDrawMode( “normal” )
–> Create Walls
local leftWall = display.newRect (-5, 0, 1, display.contentHeight)
local rightWall = display.newRect (display.contentWidth, 0, 1, display.contentHeight)
local ceiling = display.newRect (0, 0, display.contentWidth, 1)
local floor = display.newRect (0, display.contentHeight, display.contentWidth, 1)
physics.addBody (leftWall, “static”, {bounce = 0.0, friction = 10})
physics.addBody (rightWall, “static”, {bounce = 0.0, friction = 10})
physics.addBody (ceiling, “static”, {bounce = 0.0, friction = 10})
physics.addBody (floor, “static”, {bounce = 0.0, friction = 10})
physics.addBody( ceiling, “static”, { density=0, friction=0.5,bounce=0.2 } )
local xCenter = 160
local wCeil = 120
local hCeil = -5
–local ceiling = display.newRect( xCenter - wCeil*0.5, 0, wCeil, hCeil )
physics.addBody( ceiling, “static”, { density=0, friction=0.5,bounce=0.2 } )
local prevBody = ceiling
local w,h = 10,22
local halfW,halfH = 0.5*w,0.5*h
– center of body
local x = xCenter
local y = hCeil - halfH
local yJoint = y - halfH
local linkCount = 15
local heightCount = 10
local group = display.newGroup()
– rope
for i = 1, linkCount do
y = y + h
yJoint = yJoint + h
link[i] = display.newImage(“link.png” ,x-halfW, y-halfH) --) display.newRect( x-halfW, y-halfH, w, h )
–body:setFillColor( 128, 0, 0 )
physics.addBody( link[i], { density=15, friction=0.5, bounce = .2 })
local joint = physics.newJoint( “pivot”, prevBody, link[i], xCenter, yJoint )
prevBody = link[i]
group:insert( link[i] )
end
local function test ()
– From the top ****************** DOESN"T WORK ******************
– Need this to have a slow transition of the slowly removing the top link or moving it up
– until out of view then and removing it and applying the second link in the chain to become
– the first and resetting the joints so that what was originally the second is now the one
– joined ot the ceiling
link[1].height = link[1].height - 2.2
link[2].y = link[2].y - 2.2
yJoint = yJoint + h
heightCount = heightCount - 1
if(heightCount == 0) then
link[1]:removeSelf()
heightCount = 10
end
– From the bottom ****************** DOES WORK ******************
– This works fine but doesn’t look natural
–[[
if(linkCount > 0) then
link[linkCount]:removeSelf()
linkCount = linkCount - 1
end
]]
end
timer.performWithDelay(500, test, 0)[/lua]
The bit in question is the test function. If I take from the bottom that is simple right but doesn’t look like the chain is being pulled from the top. If you think about pulling a tope or chain you pull from the top so therefore that should be the one that disappears right?
The challenge I have is that I need to either slowly transition the whole chain by the height of the link and then once totally removed from sight then remove it and reapply all the joints etc to its new positions etc and join it to the ceiling. This however seems a bit of a hack.
A little help in resetting the bodies and joints would be appreciated
[import]uid: 103970 topic_id: 18288 reply_id: 70209[/import]