@Clain: Sorry, I missed your question before about subclassing. Yes, I do have subclassed sprites. Here is some code:
In my gameLayer.m I run this in the init:
//circle manager
circles = [[NSMutableArray alloc] init];
for(int n=0; n<numberOfCircles; n++) {
CGPoint pos = ccp(arc4random()%450 + 15, arc4random()%290 + 15);
circle[n] = [self addNewCirclePosition:pos scale:1.0];
[circles addObject: circle[n]];
[circle[n] setVisible:NO];
[circle[n] runAction:[FadeOut actionWithDuration:0.01]];
}
and outside of the init I have the method addNewCirclePosition:
-(CircleSprite *) addNewCirclePosition:(CGPoint)pos scale:(double)scle
{
CircleSprite *b = [[CircleSprite alloc] initWith:(NSInteger) cUpgradeLevel];
[self addChild:b z:1];
[b setScale: (float) scle];
[b setPosition: pos ];
return b;
}
- (void) dealloc {
NSLog(@"gameLayer dealloc called");
[self removeAllChildrenWithCleanup:YES];
[super dealloc];
}
and all the other game logic...
In the gameLayer.h I have this:
#define kNumberOfCircles 30
@interface GameLayer : Layer {
NSMutableArray *circles;
CircleSprite *circle[kNumberOfCircles]; //note kNumberOfCircles != numberOfCircles. Is this a problem?
//other stuff
}
-(CircleSprite *) addNewCirclePosition:(CGPoint)pos scale:(double)scle;
And then in circleSprite, which is a subclass of sprite, I basically set up an animation in the init, set an integer framecount, and then run a timer which updates framecount and sets the animation frame. The timer is unscheduled at the end of the level, or when it is restarted. In the dealloc I have:
- (void) dealloc
{
[explodeAnimation release];
[super dealloc];
}
I am most likely wrong, since I only started coding anything in about April, but I was under the impression that as long as all schedules were unscheduled (which I can confirm they are before running replaceScene with transition) then the scene should release and dealloc. I'm probably overlooking something stupid, like an alloc/release somewhere.
Any suggestions?