Hi guys,
I've read the piece on the wiki about best practices, and that all makes perfect sense. There's a couple of things I'm unclear of though, I hope you can help!
Sprites / Labels: I'm adding these to the screen in the init method of my scene. What's the best way to manage these for most efficient memory useage bearing in mind that I need to refer to these to update them? Before, I was getting the child of the layer by tag, casting it to a sprite or label, and then updating it. Is this method better or worse than declaring a CCLabel in the header file for the scene and assigning it when my label is added to the layer?
In my head, I imagine that finding the child, casting it to a type and then updating it will use more memory than simply keeping a reference to it in the class?
My second question is that I've noticed a pretty drastic drop in frame rate when I tap on the screen in my scene. I have 3 objects on the screen - a ball (a sprite that doesn't really do anything), and 2 progress timers. The values for these bars are stored in a singleton class. On touch, I'm updating their values and then calling an action on the Progress Timer which animates to it's new position.
I've noticed a drop in framerate from around 59.0FPS to around 20FPS for about 0.5 seconds, then it creeps back to 59.0FPS. I've turned off thumb compilation and I've tried compiling in release mode (for 3.0 SDK), which provides a bit of a framerate boost.
Is my problem just with the NSLogs used in debug? or do I need to be concerned that adding a few more sprites is going to kill my game? It runs in the simulator at 60FPS
Here's my code:
- (void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
if( touch ) {
CGPoint location = [touch locationInView: [touch view]];
// IMPORTANT:
// The touches are always in "portrait" coordinates. You need to convert them to your current orientation
CGPoint convertedPoint = [[CCDirector sharedDirector] convertToGL:location];
player.targetx = convertedPoint.x;
player.targety = convertedPoint.y;
//Increase HP by 10 points
gamestate.player.CurrentHP -=10; // Gamestate is my singleton
gamestate.player.CurrentMP -=20;
float HPpercent = ((float)gamestate.player.CurrentHP / (float)gamestate.player.MaxHP) *100;
float MPpercent = ((float)gamestate.player.CurrentMP / (float)gamestate.player.MaxMP) *100;
//progress and mpprogress are Progress Timer objects which are children of the layer and a reference is kept within the scene's class
[progress runAction:[CCRepeat actionWithAction:[ProgressFromTo actionWithDuration:0.5f from:[progress percentage] to:HPpercent] times:1]];
[mpprogress runAction:[CCRepeat actionWithAction:[ProgressFromTo actionWithDuration:0.5f from:[mpprogress percentage] to:MPpercent] times:1]];
}
}
Thanks!