views:

711

answers:

3

I'm writing a game with cocos2d and I have noticed that the frame rate drops as the game progresses. I've checked for leaks but everything looks fine so I'm at a loss as to what to do next. Sorry if this is a really basic question but what sort of factors cause frame rate loss?

The problem seems to get worse when I clear the sprites from a layer. Sometimes the framerate jumps back to 60 but occasionally it drops down to 30 or lower and never recovers. After a few minutes the animations are noticably slower and the game pretty much grinds to a halt. I'm not sure if this is specific to cocos2d or a common issue in game development, but it renders the game unplayable :(

+1  A: 

Your framerate will drop if you add more sprites, obviously, because it has more to process.

Now, I do not know anything about cocos2d, but when you are "clearing the sprites from a layer", it sounds as though it simply hides them from view in addition to storing the fact that they are now hidden.

Maybe try and use fewer sprites?

Cyclone
+2  A: 

How are you testing for memory leaks? I don't think you should rule that out as the cause until you are absolutely certain because that sounds like classic "memory leak behaviour".

Also make sure you don't have something like a log or something in memory which is continually getting larger and larger every frame (I say so because that's happened to me in the past).

Also make sure you aren't continually loading new objects and/or sprites as your game progresses. Try and keep all your load calls in the initialization segment of your logic.

Chris Reynolds
I'm using the Leaks instruments tool. Upon more careful inspection I did find a leak and it turns out that there others have had similar issues with the cocos2d particle system.http://www.cocos2d-iphone.org/forum/topic/177Thanks for your advice and I'll keep an eye out for more pitfalls.
Stu
+1  A: 

Are you reusing preloaded textures? If you aren't you should. Loading the same texture again and again is both slow, and is a leak.

Additionally, are you releasing textures you're done with? Even though the sprite is gone the texture is still there.

deeb