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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | 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 ) |
I tested.
obviously I don't have your images so I used display.newCircle (which would use less memory)
using this memory function:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | local lastCheck = {sysMem = 0, textMem = 0} Runtime:addEventListener('enterFrame', function() -- watch for leaks collectgarbage() local sysMem = collectgarbage("count") * .001 local textMem = system.getInfo( "textureMemoryUsed" )*.000001 if lastCheck.sysMem ~= sysMem or lastCheck.textMem ~= textMem then lastCheck.sysMem = sysMem lastCheck.textMem = textMem print ("Mem: " .. math.floor(sysMem*1000)*.001 .. "MB \t TextMem: " .. math.floor(textMem*1000)*.001 .. "MB") end end) |
Thank you anddrewscott for the test, now i will work on the rope to improve the algorithm
but i continue with some of doubts about how a rope made with corona can behave on device, because on my opinion the game cut the rope is so fluid, the rope is perfect, and i dont know if this performance is possible with corona.