I’m trying to better understanding setting up a loop to join objects. Right now I have them individually (see a small clip code below).
I know there has to be a shorter why using the i = 1, 3 do type of code. I’ve tried to set it up but no luck.
My actual link will have more than three links but I thought this would work for example purposes.
I’d appreciate any help in setting up this loop. Thanks Lori :rolleyes:
--LINKS
local myCircleA = display.newImage (“Images/rockLink.png”)
myCircleA.x = 105; myCircleA.y = 370
physics.addBody(myCircleA,“static”,{radius=10, bounce=0.5, friction =0.953})
local myCircleB = display.newImage (“Images/rockLink.png”)
myCircleB.x = 180; myCircleB.y = 280
physics.addBody(myCircleB,“static”,{radius=10, bounce=0.5, friction =0.953})
-------------------------------------
local linkA = display.newImage(“Images/link.png”)
linkA.x = 110; linkA.y=360
linkA.rotation=45
physics.addBody( linkA, { density=1.0, friction=0.5, bounce=0.5 } )
physics.newJoint( “pivot”, linkA, myCircleA, myCircleA.x, myCircleA.y)
-------------------------------------
local linkB=display.newImage(“Images/link.png”)
linkB.x = 120; linkB.y=348
linkB.rotation=45
physics.addBody( linkB, { density=1.0, friction=0.5, bounce=0.5 } )
physics.newJoint( “pivot”, linkB, linkA, linkA.x, linkA.y)
---------------------------------------
local linkC=display.newImage(“Images/link.png”)
linkC.x = 130; linkC.y=336
linkC.rotation=45
physics.addBody( linkC, { density=1.0, friction=0.5, bounce=0.5 } )
physics.newJoint( “pivot”, linkC, linkB, linkB.x, linkB.y)