Please help me in optimizing the code below , it hangs in few seconds.-
–
– main.lua
–
– Your code here
local physics = require “physics”
physics.start()
physics.setGravity( 0, 0)
local math = require(“math”)
display.setStatusBar(display.HiddenStatusBar)
local outermainarray={}
local h2=820;
local dotsforshootarray = {}
local bulletanglearray={}
local dotarray={}
local pausedcircle11
local pausedcircle
local id=1;
local DX, DY = 3, 3
local XMIN, XMAX = 1, display.contentWidth-1
local YMIN, YMAX = 20, display.contentHeight-1
_W = display.contentWidth; – Get the width of the screen
_H = display.contentHeight; – Get the height of the screen
motionx = 0; – Variable used to move character along x axis
speed = 2; – Set Walking Speed
local w = display.contentWidth
local h = display.contentHeight
local centerX = display.contentCenterX
local centerY = display.contentCenterY
local myTable = {}
local rect
local Cos = math.cos
local Sin = math.sin
local Rad = math.rad
local Atan2 = math.atan2
local Deg = math.deg
local function arc(x, y, radius, theta1, theta2, width, detail)
local vertices = {};
local k = 1;
– UPRIGHT - Comment out UPSIDE DOWN if using
for i = (360 - theta2), (360 - theta1), detail
do
vertices[k] = radius*math.cos(2*math.pi*(i / 360));
vertices[k + 1] = radius*math.sin(2*math.pi*(i / 360));
k = k + 2;
end
for i = ((360 - theta1) - ((360 - theta1) % detail)), (360 - theta2), -detail
do
vertices[k] = (radius - width)*math.cos(2*math.pi*(i / 360));
vertices[k + 1] = (radius - width)*math.sin(2*math.pi*(i / 360));
k = k + 2;
end
return display.newPolygon(x, y, vertices), vertices;
end
local function spawnnewloop( event )
print(myTable)
local function spawnnewrings(event)
for s=#myTable,1,-1 do
if myTable[s]~=nil then
if myTable[s].y>1200 then
transition.cancel( myTable[s] )
display.remove(myTable[s])
myTable[s] = nil
end
end
end
if #myTable<200 then
spawnnew()
end
end
for j=#myTable,1,-1 do
if(myTable[j]~=nil) then
transition.to(myTable[j],{time=2000, y=myTable[j].y+1200,onComplete=spawnnewrings})
end
end
end
function spawnBubble(ringx,ringy,ringradi,ringstart,ringend,bubblex,bubbley,rotationspeed)
– add bottom arch 2
local circle2bubble =display.newCircle(display.contentWidth/2,display.contentHeight/2,25)
circle2bubble:setFillColor( 0, 1, 1 )
circle2bubble.x = bubblex
circle2bubble.y = bubbley-364
circle2bubble.linearDamping=0
circle2bubble.myName=“bubble”
physics.addBody(circle2bubble)
transition.to(circle2bubble,{time=1000, y=bubbley,x=bubblex})
circle2bubble.isSensor = true
myTable[#myTable+1]=circle2bubble
transition.to(circle2,{time=1000, y=ringy,x=ringx})
end
function spawnnew( event )
if (myTable[#myTable]~=nil) then
h2=myTable[#myTable].y-200
end
for m = 1, 5 do
if(m%5==1) then
spawnBubble(384,h2, 2, -95,2,384,h2,6.5)
end
if(m%5==2) then
spawnBubble(160,h2, 2, -95,2,160,h2,6.5)
end
if(m%5==3) then
spawnBubble(520, h2, 2, -95,2,520,h2,6.5)
end
if(m%5==4) then
spawnBubble(190, h2, 2, -95,2,190,h2,6.5)
end
if(m%5==0) then
spawnBubble(500, h2, 2, -95,2,500,h2,6.5)
spawnnewloop()
–h2=h2+700
end
h2=h2-200
end
end
spawnnew()