It seems my game is having performance issues after some gameplay time... so I have been researching a bit, and I have come up with many questions:
1- Let's say my game spawns about 3 sprites every... half a second. Like this way:
CCSprite *sprite = [CCSprite spriteWithFile:@"Something.png"];
[self addChild:sprite];
[myArray addObject:sprite]; // For later doing stuff with these sprites
Is that a proper way for spawning said sprites? Is there a more efficient way? I have been looking around, and it seems like creating my sprites with a spritesheet is more efficient, like, instead doing this:
sheet = [CCSpriteSheet spriteSheetWithFile:@"texture.png" capacity:50]; // What is capacity for?
[self addChild:sheet];
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"texture.plist"]; // I am not 100% sure what this does though
sprite = [CCSprite spriteWithSpriteFrameName:@"Test1.png"];
[sheet addChild:sprite];
I made the texture.png and texture.plist using that online tool which I forgot the name ("Zwoopsomething 0.0"). The texture has three sprites, Test1.png, Test2.png, Test3.png.
2- Audio. My game, currently, just has 2 audio files. Both are .mp3, one is a long soundtrack while the other is just a sound effect. The soundtrack is my background music, called like this:
[[SimpleAudioEngine sharedEngine] playBackgroundMusic:@"GameBGM.mp3" loop:YES];
and the sound effect is, mostly depending on the player, called around once every half a second.. or twice. Like this:
[[SimpleAudioEngine sharedEngine] playEffect:@"Effect.mp3"];
I heard that there were some memory problems regarding usage of .mp3 files, but that was months ago, and I am not sure if there still are. I was planning on changing at least the sound effect to .wav. What do you recommend me? I am probably adding other 3-4 audio files for the game.
3- Scheduling.
On my init method, I have 7 schedules. Each with different intervals (and one with none, meaning it will be executed as many times as it can. It is for collision checking).
Now, 7 schedules... All of them with less than 1 second interval. Can that really affect performance? (That sounds pretty dramatic to me, I guess they do affect.)
My idea for some kind of fix was to instead make 7 CGFloats, each representing a timer for each method call, and then schedule one single method. This method will increase the value of all 7 floats, and when a float hits the adequate value, it will reset and call the method it is representing.
That sounds like a fairly good idea, but only if 7 schedules with less than 1 second intervals really affect performance...
4 - What and when shall I release?
Look at the sprite I made in the first question. Am I supposed to release it sometime?
[sprite release];
Or are they property of cocos2d when I created them and will be automatically released? In that case, when will they be auto-released? When removed from the scene's children?
My project now crashes and closes on an almost fixed part of the progress (think of it like a racing game with obstacles constantly appearing, the game crashes at around 1500m-1900m of distance... GDB: Program received signal "0" is the last thing it says)
5 - Removing unused textures.
This might be one of the main problems... I placed this method in the schedule method that has no interval:
[[CCTextureCache sharedTextureCache] removeUnusedTextures];
And when I test it... well, I get lots, lots of messages saying "removing unused texture blah"... lots of times... lots... Now, that makes me think... how are they considered "unused"?