Hello everyone, i am thinking on implement code to create a rope, grabbing a ball, we have some examples of code and examples of games like cut the rope, but i have some troubles and doubts about a rope performance made with corona, because i can see on example edited by me that the performance isnt the better, maybe because i work little with this
Anyone can talk a little about this subject, give your opinions etc
[code]
display.setStatusBar (display.HiddenStatusBar)
–> Start Physics
local physics = require (“physics”)
physics.start ()
physics.setGravity (0, 9.8)
–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 = 160
local wCeil = 120
local hCeil = -5
local xCenter1 = 160
local wCeil1 = 120
local hCeil1 = -5
local prevBody = ceiling
local prevBody1 = ceiling
local w,h = 10,10
local halfW,halfH = 0.5*w,0.5*h
local w1,h1 = 10,10
local halfW1,halfH1 = 0.5*w1,0.5*h1
– center of body
local x = xCenter
local y = hCeil - halfH
local yJoint = y - halfH
local x1 = xCenter1
local y1 = hCeil1 - halfH1
local yJoint1 = y1 - halfH1
– rope
for i = 1, 30 do
y = y + h
yJoint = yJoint + h
y1 = y1 + h1
yJoint1 = yJoint1 + h1
local body = display.newImage(“rope.png” ,x-halfW, y-halfH)
local body1 = display.newImage(“rope.png” ,x-halfW1, y-halfH1)
physics.addBody( body, { density=40, friction=0.5, bounce = .2 })
physics.addBody( body1, { density=40, friction=0.5, bounce = .2 })
local joint = physics.newJoint( “pivot”, prevBody, body, xCenter, yJoint )
local joint2 = physics.newJoint( “pivot”, prevBody1, body1, xCenter1, yJoint1 )
prevBody = body
prevBody1 = body1
end
– final body
local body = display.newImage(“soccerball.png”, x,y -30);
local r = body.height *0.5
physics.addBody( body, { density=5, friction=0, bounce=0, radius=r })
body:applyLinearImpulse(100, 0, body.x, body.y)
local joint = physics.newJoint( “pivot”, prevBody, body, xCenter, y )
local joint2 = physics.newJoint( “pivot”, prevBody1, body, xCenter1, y1 )
[/code] [import]uid: 26056 topic_id: 15500 reply_id: 315500[/import]