Hi all,
I have a problem with major slowdown when calling animations that I have init'd in a subclassed sprite. I have 10 imaginatively named ZombieSprite's, which, upon a collision with a bullet will run a death animation. However, upon the coliision I lose about 10-15fps for each ZombieSprite that gets hit. I've spent about 4 hours trying to sort this out, so any help or suggestions would be much appreciated. Here's the ZombieSprite code:
.m
-(id) init
{
self = [super init];
if (self)
{
[self initWithFile:@"zombie1frame1.png"];
self.walkAnimation = [[[Animation alloc] initWithName:@"walkAnimation" delay:0.1f]retain];
[walkAnimation addFrameWithFilename:@"zombie1frame1.png"];
[walkAnimation addFrameWithFilename:@"zombie1frame2.png"];
[walkAnimation addFrameWithFilename:@"zombie1frame1.png"];
[walkAnimation addFrameWithFilename:@"zombie1frame3.png"];
[self addAnimation:walkAnimation];
actionWalkAnimation = [Animate actionWithAnimation: walkAnimation restoreOriginalFrame:NO];
[actionWalkAnimation retain];
actionWalkForever = [RepeatForever actionWithAction:actionWalkAnimation];
[actionWalkForever retain];
//and the death animation
deathAnimation = [[[Animation alloc] initWithName:@"deathAnimation" delay:0.05f]retain];
[deathAnimation addFrameWithFilename:@"zombie1frame1.png"];
[deathAnimation addFrameWithFilename:@"zombie1frame2.png"];
[deathAnimation addFrameWithFilename:@"zombie1frame3.png"];
[deathAnimation addFrameWithFilename:@"zombie1frame4.png"];
[deathAnimation addFrameWithFilename:@"zombie1frame5.png"];
[deathAnimation addFrameWithFilename:@"zombie1frame6.png"];
[deathAnimation addFrameWithFilename:@"zombie1frame7.png"];
[deathAnimation addFrameWithFilename:@"zombie1frame8.png"];
[deathAnimation addFrameWithFilename:@"zombie1frame9.png"];
[deathAnimation addFrameWithFilename:@"zombie1frame10.png"];
[self addAnimation:deathAnimation];
actionDeathAnimation = [Animate actionWithAnimation: deathAnimation restoreOriginalFrame:NO];
[actionDeathAnimation retain];
/////rest of init code etc
}
-(void) showDeath
{
[self stopAllActions];
[self runAction: actionDeathAnimation];
}
@end
////////////////////////////////////////////////
.h
@interface ZombieSprite : Sprite
{
Animation *walkAnimation;
Action *actionWalkAnimation;
Action *actionWalkForever;
Animation *deathAnimation;
Action *actionDeathAnimation;
}
@property (nonatomic, retain) Animation *walkAnimation;
@property (nonatomic, retain) Animation *deathAnimation;
@property(readwrite,retain) Action * actionWalkAnimation;
@property(readwrite,retain) Action * actionWalkForever;
@property(readwrite,retain) Action * actionDeathAnimation;
@end
/////////////////////////////////////
in the main game layer I have the following that calls the death animation on the zombieSprite. Zombie[m] is just one of the 10 ZombieSprites that I've made and stored in an array.
//code for collision, all good and thoroughly tested
[zombie[m] showDeath];
So calling this runs the animation which is great. But I also lose 10-15fps, and so the game grinds to a halt pretty soon!
Any suggestions? All help will be appreciated :)