hi, this is a newbie question, this is my first attempt to delve into corona.
i’ve taken the rope demo and tried to wrap it into function.
but after the first rope all the ropes are eager to attach themselves to the first rope. can you help?
[lua]display.setStatusBar (display.HiddenStatusBar)
require “gameUI”
display.newImage(“bg.jpg”);
–> Start Physics
local physics = require (“physics”)
physics.start ()
physics.setGravity (0, 9.98)
–physics.setDrawMode (“hybrid”)
–> Create Walls
local leftWall = display.newRect (0, 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})
local xCenter = 240
local wCeil = 120
local hCeil = -5
local ceiling = display.newRect( xCenter - wCeil*0.5, 0, wCeil, hCeil )
ceiling.strokeWidth = 20
ceiling:setFillColor(140, 140, 140)
physics.addBody( ceiling, “static”, { density=0, friction=0.5,bounce=0.2 } )
local prevBody = ceiling
local w,h = 10,10
local halfW,halfH = 0.5*w,0.5*h
–> Rope Function
local function makerope(where,inst )
local prevbody=nil
local body=nil
– center of body
local y = hCeil - halfH
local yJoint = y - halfH
– rope
for i = 1, 15 do
y = y + h
yJoint = yJoint + h
local body = display.newImage(“rope.png” ,where-halfW, y-halfH) --) display.newRect( x-halfW, y-halfH, w, h )
–body:setFillColor( 128, 0, 0 )
physics.addBody( body, { density=25, friction=0, bounce = .8 })
local joint = physics.newJoint( “pivot”, prevBody, body, where, yJoint )
prevBody = body
end
end
local rope1=makerope(10)
local rope2=makerope(40)[/lua] [import]uid: 12530 topic_id: 7714 reply_id: 307714[/import]
[import]uid: 12530 topic_id: 7714 reply_id: 27369[/import]