Hi,
I have a really big problem -
I’ve created a physics based game that contantly adds and subtracts physical objects in and from a Table.
The project is barely 20mb, everything runs smoothly, but inside the scene with the physical objects, it kills even a nexus7 after some point…
I’m writing down the main function that handles the physical objects inside the table…
Please, If you see anything wrong here that might indicate a memory problem please write it down - thank you
function newCrate()
local crate=""
local isPopped=0
local check=math.random(1,4)
if(check==1) then
crate=display.newImage(“Photos/crate.png”)
elseif (check==2) then
crate=display.newImage(“Photos/crate2.png”)
elseif(check==3) then
crate=display.newImage(“Photos/crate3.png”)
else
crate=display.newImage(“Photos/crate4.png”)
end
table.insert(t,crate)
crate.width = 50
crate.height= 50
crate.y=-70
local px=math.random(50,900)
crate.x= px
local rotate=math.random(0,359)
crate.rotation=rotate
physics.addBody(crate, “dynamic”, {bounce=0.5})
local pl=math.random(0.5,2.5)
crate.linearDamping =pl
local check2=(math.random(1,2))
if(check2==1) then
local moveTrans=transition.to(crate,{time=8000, rotation=rotate+360})
else
local moveTrans=transition.to(crate,{time=8000, rotation=rotate-360})
end
local function reventar(event)
if(event.object2.class==“ball”) then
event.object1.fastkill = true
elseif(event.object1.class==“ball”) then
event.object2.fastkill = true
end
end
local function suck(obj)
local good=display.newImage(“Photos/Spiral.png”)
good.x=obj.x; good.y=obj.y
ball.ballX(obj)
local trans2=transition.to(good, {time=300, xScale=0.5,yScale=0.5,alpha=0,rotation=180})
local trans=transition.to(obj, {time=250, width=0,height=0,x=obj.x, y=obj.y,alpha=0})
timer.performWithDelay(300,function()
if isPlaying then
trans=nil;good:removeSelf(); good=nil;trans2=nil
end
end)
end
local function loop(event)
for i = #t, 1, -1 do
local object = t[i]
if(object~=nil) then
if(isPaused) then
object.isVisible=false
else
object.isVisible=true
end
if(slowMo==false) then
object.linearDamping=pl;
else
object.linearDamping=5;
end
if(object.y~=nil) and object.y>700 then
score.setScore(9999)
local child = table.remove(t, i)
if child ~= nil then
child:removeSelf()
child = nil
check=nil
isPopped=nil
px=nil;pl=nil;rotate=nil
crate=nil
check2=nil
Runtime:removeEventListener(“enterFrame”, loop)
Runtime:removeEventListener(“collision”,reventar)
if(moveTrans~=nil) then
transition.cancel(moveTrans)
moveTrans=nil
end
end
elseif object.fastkill then
if isDouble then
score.setScore(200)
else
score.setScore(100)
end
if(isPopped~=nil) then
isPopped=isPopped+1
timer.performWithDelay(isPopped*50,function()
local popSound = audio.play( pop )
isPopped=0
end)
end
ball.addOne()
suck(object)
local child = table.remove(t, i)
timer.performWithDelay(300,function()
if child ~= nil and isPlaying then
child:removeSelf()
child = nil
check=nil
check2=nil
isPopped=nil
crate=nil
px=nil;pl=nil;rotate=nil
popSound=nil
Runtime:removeEventListener(“enterFrame”, loop)
Runtime:removeEventListener(“collision”,reventar)
if(moveTrans~=nil) then
transition.cancel(moveTrans)
moveTrans=nil
end
end
end)
end
end
end
end
for i=1,#t do
t[i].id = i
end
Runtime:addEventListener(“enterFrame”, loop)
Runtime:addEventListener(“collision”,reventar)
end