I see this line:
> storyboard.purgeOnSceneChange = true
on main.lua. I don’t see anything else.
I’m kinda suspectings this bit of code below:
<<<<
local fg = require “classes.fglobal”
local pg = require “classes.proj_global”
local ps = require “classes.lib_particle_candy”
local fx = require “classes.ekfxlib”
local tx = require “classes.ektx”
local ot = require “classes.objtype”
local sg = require “classes.scr_global”
local sp = { }
local sp_mt = { __index = sp }
local physics = require “physics”
local easingx = require “classes.easingx”
sp.view = nil – main display group
local UP_SPAWN_LIMIT = 300
local WIDTH = 50
sp.createView = function ()
sp.view = display.newGroup ()
end
sp.removeView = function ()
--self.stopped = true
if sp.view == nil then
return;
end
sp.view:removeSelf() --!
sp.view = nil
end
sp.new = function(name, objNum, objTypeA ) – constructor
local newObject = {
myName = name or “unnamed”,
stopped = false,
unloading = false,
objType = objTypeA or ot.CIRCLE,
average = objNum or 3,
allStuff = {},
}
return setmetatable (newObject, sp_mt)
end
function sp:status ()
print ("objType "… self.objType)
print ("average “… self.average)
print (”#allStuff " … #self.allStuff)
end
------- Methods -----
function sp:spawnStuff (sDelay)
if self.stopped == true then return; end
local pscale = math.random (3,6) / 10
local pradius = 20
local function onCollision( self, event )
– occurs, when objects collide with the obstacle
if event.phase == “began” then
if event.other.myName == “sat1” then
self.kill = true
if (self.myName == ot.SPIKE1) or (self.myName == ot.SPIKE2) or (self.myName == ot.SPIKE3) then
self.kill = false
end
elseif (event.other.myName == “player1”) then
if (self.myName==ot.SPIKE1) or (self.myName==ot.SPIKE2) or (self.myName==ot.SPIKE3) or (self.myName == ot.HEART) then
self.kill = true
end
end
end
end
local function onObjShowComplete( target )
– if sp.stopped == true then return; end
if target == nil then return; end
if self.unloading then return; end
if target.kill then return; end
physics.addBody (target, { density = 1.0, friction = 0.3, bounce = 0.2, radius = pradius * pscale} )
target.collision = onCollision
target:addEventListener (“collision”, target)
--taret.myName = “obj” … math.random (100)
local force = math.random( 1, 5 )
if math.random (2) == 1 then force = force * -.5; end
target:applyLinearImpulse( force / 5, force, target.x, target.y )
local torque = math.random (5, 150)
if math.random (2) == 1 then torque = torque * -1; end
target:applyTorque (torque)
end
– define needed variables
local x
local y
local size = 50
local delay = 50
– get random values for the objects parameters
x = math.random( sg.left + 100, sg.right - 100)
y = math.random( 0, UP_SPAWN_LIMIT )
– dprint (pg.imgPath)
if self.objType == ot.STAR1 then
pradius = 32
self.allStuff[#self.allStuff + 1] =
display.newImageRect ( pg.imgPath … “mbo1” … “.png”, 64 *pscale, 64 *pscale)
elseif self.objType == ot.STAR2 then
pradius = 32
self.allStuff[#self.allStuff + 1] =
display.newImageRect ( pg.imgPath … “mbo2” … “.png”, 64 *pscale, 64 *pscale)
elseif self.objType == ot.STAR3 then
pradius = 32
self.allStuff[#self.allStuff + 1] =
display.newImageRect ( pg.imgPath … “mbo3” … “.png”, 64 *pscale, 64 *pscale)
end
print ("Menu–>objType "… self.objType)
--print ("average “… self.average)
--print (”#allStuff " … #self.allStuff)
--print ("test # "… #self.allStuff)
local stuff = self.allStuff [#self.allStuff]
stuff.x = x
stuff.y = y
sp.view:insert (stuff)
--stuff.linearDamping = 0.4
--stuff.angularDamping = 0.6
stuff.alpha = 0
stuff.xScale = 0.1
stuff.yScale = 0.1
stuff.rotation = math.random (360)
stuff.myName = self.objType; – … math.random (100)
stuff.kill = false
if fg.doDebug then
stuff.tHandle = transition.to( stuff, { transition = easing.outExpo, time = 500, xScale = 1, yScale = 1, alpha = 1, delay = sDelay, onComplete = onObjShowComplete } )
else
stuff.tHandle = transition.to( stuff, { transition = easingx.easeOutElastic, time = 500, xScale = 1, yScale = 1, alpha = 1, delay = sDelay, onComplete = onObjShowComplete } )
end
end
function sp:removeAndAddStuff()
if self.stopped == true then return; end
local allStuff = self.allStuff
for i=#allStuff, 1, -1 do
--print (“y=”…oneStuff.y)
if allStuff[i] then
if (allStuff[i].y > sg.bottom + WIDTH ) or
(allStuff[i].y < sg.top - WIDTH ) or
(allStuff[i].x < sg.left - WIDTH ) or
(allStuff[i].x > sg.right + WIDTH ) then
--oneStuff:removeSelf()
transition.cancel (allStuff[i].tHandle)
local oneStuff = allStuff[i]
display.remove (oneStuff) – safest way?
--display.remove (allStuff[i]) – another way to remove object.
--allStuff[i]:removeSelf() – ?!
oneStuff = nil
table.remove (allStuff,i)
end
end
end
– oneStuff = nil
local j = self.average - #self.allStuff
– print (“j:”…j…" #allStuff:"…#self.allStuff)
if j > 0 then
for k = 1, j do
sp.spawnStuff (self, 0)
end
end
end
function sp:stop () – stop spawning
self.stopped = true
end
function sp:start()
self.stopped = false
end
function sp:unload () – stop everything and remove everything.
self.stopped = true
self.unloading = true
print “sp: unload started…”
for i = 1, #self.allStuff do
if self.allStuff[i] then
transition.cancel (self.allStuff[i].tHandle)
local oneStuff = table.remove (self.allStuff,i)
if oneStuff ~=nil then
oneStuff:removeSelf()
oneStuff=nil
end
end
end
end
function sp:startCreatingStuff( )
– create the objects
self.stopped = false
for i = 1, self.average do
sp.spawnStuff (self, 0 )–i*math.random (200,500))
end
end
return sp