Hi, I’m trying to add a sort of magnetic attraction effect to my game by using rings shrinking towards a centre point. Without this code my game runs at a very solid frame rate on my HTC One X (hovers around 60 fps). When I add the code, it drops to about 12 fps. Any ideas? Thanks for looking.
local mRand = math.random local rings = display.newGroup() local spawnRing = function(params) local ring = display.newCircle(params.group, \_W\*0.5 + 100, \_H\*0.5, params.radius) ring : setFillColor(0, 0, 0, 0) ring.strokeWidth = params.thickness ring : setStrokeColor(255, 255, 255) ring.radius = params.radius ring.reachedCentre = false ring.alpha = 0.5 function ring : destroy() display.remove(self) self = nil end return ring end for i = 1, 8 do spawnRing({radius = i\*44 + mRand(-5, 5), thickness = mRand(1, 6), group = rings}) end local shrinkRings = function() for i = 1, rings.numChildren do if rings[i] then rings[i] : scale(0.99, 0.99) rings[i].radius = rings[i].radius\*0.99 if rings[i].radius \<=100 and rings[i].reachedCentre == false then rings[i].reachedCentre = true spawnRing({radius = 356, thickness = mRand(1, 6), group = rings}) elseif rings[i].radius \<=50 then rings[i] : destroy() end end end end Runtime : addEventListener("enterFrame", shrinkRings)