Performance issues in game

I have a game with continuously moving levels. At the end of each level next level objects are spawned and at the beginning of the next level, the objects of the previous level are destroyed.

But i have serious performance issues. After some 5 levels the game gets ridiculously slow. I have a continuously moving gameLayer in which I insert all layer objects.

Is the performance issue due to the fact that the gameLayer is continuously moving in spite of each level object being dynamically spawned and destroyed? How do I resolve this?

Please help me out here…

Here is a sample code of how I move levels…

[lua]local gameLayer = display.newGroup()
local playerGroup = display.newGroup()
local levelObjects = display.newGroup()

gameLayer:insert(levelObjects)
gameLayer:insert(playerGroup)

local myCircle = display.newCircle(playerGroup, 100, 100, 30 );
physics.addBody( myCircle, { density=3.0, friction=0.5, bounce=0.3 } )

local myRectangle = display.newRect(levelObjects, 0, 300, 480, 20);
physics.addBody( myRectangle, “static”, { density=3.0, friction=0.5, bounce=0.3 } )

local myRectangle = display.newRect(levelObjects, 100, 280, 20, 20);
physics.addBody( myRectangle, “static”, { density=3.0, friction=0.5, bounce=0.3 } )

local function moveLevel()
myCircle.x = myCircle.x + 10
gameLayer.x = gameLayer.x-10
end

Runtime:addEventListener(“enterFrame”, moveLevel)[/lua] [import]uid: 64174 topic_id: 13291 reply_id: 313291[/import]

are you removing the old objects from memory
[import]uid: 7911 topic_id: 13291 reply_id: 48804[/import]

Yes! i use object:removeSelf() for each object when destroying levels…

But the gameLayer where I insert level objects is the same for all levels. So the game layer goes on and on beyond the screen. Is this the reason for the poor performance?

[import]uid: 64174 topic_id: 13291 reply_id: 48809[/import]

so u saying gameLayer just keeps increasing in size
if so then yes it would be better to set gameLayer to a size and at beginning of each level reset it’s pos [import]uid: 7911 topic_id: 13291 reply_id: 48812[/import]

yes thanks! I have a tentative solution!

Since the levels are continuous,i.e one immediately following the other, I have 2 gamaLayers and load levels alternatively. level1 in gamelayer1, level2 in gameLayer2,reset gameLayer1 and load level3 in gameLayer1, reset gameLayer2 and load level4 in gameLayer2, and so on.

The problem here is how do I include the player object. I do not think Box2D works well in collision of objects in different layers.
EDIT : scratch this solution… i realize this is a stupid one :frowning:
[import]uid: 64174 topic_id: 13291 reply_id: 48824[/import]

http://uploading.com/files/5368f437/scene03.lua/
http://uploading.com/files/edfeabd5/build.settings/
http://uploading.com/files/49c5bc1m/main.lua/
http://uploading.com/files/a2dfc14f/scene01.lua/
http://uploading.com/files/7f72maam/scene02.lua/

@jstrahan

This is a sample of my game… the level moves by loading the objects from the scene files.

the main gamelayer moves continuously… but the width of the gamelayer doesn’t increase, while the gamelayer.x value decreases forever…(as printed in the moveLevel function)

can you suggest any solution here? [import]uid: 64174 topic_id: 13291 reply_id: 48883[/import]

on my way home from work I’ll check it out when I get there [import]uid: 7911 topic_id: 13291 reply_id: 48885[/import]

Sure sure… take your time! and thanks! :slight_smile: [import]uid: 64174 topic_id: 13291 reply_id: 48886[/import]

theres a memory leak when removing groups you need to remove all children first then remove the group
link: http://developer.anscamobile.com/reference/index/groupremove
read the remarks at the bottom
maybe this is your problem [import]uid: 7911 topic_id: 13291 reply_id: 48914[/import]

Nop. that was not the prob…
Solved the problem though.
Used director class…

Thanks for the help!
[import]uid: 64174 topic_id: 13291 reply_id: 49208[/import]