Hey all, I have a really annoying problem when I play a sprite animation from a spritesheet.
It will very quickly display all the entire image (consisting of all my individual sprite frames) before playing the sprite animation. This always happens, but is especially noticeable when using "replaceScene" on the director (when it's init'd). It doesn't happen on repeating the animation. The effect is an annoying "flicker".
My SleepScene.h, a subclass of CCLayer
-(void) createSleepSprite{
sleepSpriteSheet = [CCSpriteSheet spriteSheetWithFile:@"halfawake.png"];
[self addChild:sleepSpriteSheet];
// create the sprite
sleepSprite = [CCSprite spriteWithTexture:sleepSpriteSheet.texture rect:CGRectMake(0, 0, 279.05f, 266.05f)];
[sleepSpriteSheet addChild:sleepSprite];
//Get standard scale
float originalScale = sleepSprite.scale;
//Double back to our size
sleepSprite.scale = originalScale * 2;
// position the sprite in the center of the screen
CGSize s = [[CCDirector sharedDirector] winSize];
sleepSprite.anchorPoint = ccp(0,0);
sleepSprite.position = ccp(0, 80 );
// create the animation
sleepAnimation = [CCAnimation animationWithName:@"ha" delay:0.1];
//Make the frames
int frameCount = 0;
for (int y = 0; y != 4; y++) {
for (int x = 0; x != 6; x++) {
// create an animation frame
CCSpriteFrame *frame = [CCSpriteFrame frameWithTexture:sleepSpriteSheet.texture rect:CGRectMake(x*140, y*134, 139.05f, 133.05f) offset:ccp(0,0)];
[sleepAnimation addFrame:frame];
frameCount++;
// stop looping after we've added 12 frames
if (frameCount == 25)
break;
}
}
}
-(id)init {
self = [super init];
if (self) {
self.isTouchEnabled = YES;
[self runSleepSprite];
}
return self;
}
(void) runSleepSprite{
[self createSleepSprite];
// create the action
id sleepAction = [CCAnimate actionWithAnimation:sleepAnimation restoreOriginalFrame:YES];
id repeat = [CCRepeatForever actionWithAction:sleepAction];
[sleepSprite runAction:repeat];
}