Hi there,
I have surfed the boards for two months now, yet this is my first post.
I have a problem which I hope is easy to spot:
- I have a game which creates multiple instances of solid color circles. Now the game starts OK and performance is acceptable on iPhone5 but as I go through the level I noticed a bit of a slow down in spawning and circles becomes less sensitive to touch (So to collide with each other). I don’t think it is a memory leak issue since if I go out of the composer scene i.e restart the level performance is back again. Could it be that I am creating too many circles with physics/touch etc. If so I am removing objects and nii them on collision; so effectively they are at any given time only 20. Am I correct?
Note in a single level around 500-2000 of these circles are created and removed but as said before only 20 remain on screen and not removed at any point in the game.
-
Should I also remove the circles from table as well?
-
Am I effectively removing the timer using timerid_drawCircle = nil in that way (Since the objects/circles are spawned)?
Also do I really have to remove the timer when it only loops once and will effectively cancel it self.
Here is my code.
Thanks in advance.
-- Draw Circle local function drawCircle(xPos, yPos, radius, cirName, cirDelay) local timerid\_drawCircle = timer.performWithDelay(cirDelay, function() local randcol = math.random( 1, 10 ) local r = colorTable[randcol][1] local g = colorTable[randcol][2] local b = colorTable[randcol][3] local myCircle = display.newCircle( xPos, yPos, radius ) myCircle:setFillColor( r/255, g/255, b/255 ) myCircle.myName = cirName myCircle.myColor = r..","..g..","..b sceneGroup:insert( myCircle ) --So to be removed when scene is changed --Insert circle into table circleTable[#circleTable+1] = myCircle --This is faster than one below --table.insert(circleTable, myCircle) physics.addBody( myCircle, { radius=cirRadius, density=3.0, friction=0.5, bounce=0.3 } ) myCircle.gravityScale = 0 -- Make the myCircle instance respond to touch events myCircle:addEventListener( "touch", onTouch\_OneDir ) -- Detect pre collisions --myCircle.preCollision = onPreCollision --myCircle:addEventListener( "preCollision", myCircle ) -- Detect collisions myCircle.collision = onLocalCollision myCircle:addEventListener( "collision", myCircle ) end, 1) timerid\_drawCircle = nil end --Now we will loop the below 20x initially to create 20 circles for i = 1, 20, 1 do circleRGB(xPos, yPos, cirRadius, cirName, math.random( 0, 2000 )) end --Then when each two circles collide another two are created in place using the same code