Wednesday, March 10, 2010

Animate sprite

sheet99 = [CCSpriteSheet spriteSheetWithFile:@"fan_l1l2_left.png" capacity:12];
[self addChild:sheet99 z:4 tag:kTagSpriteSheet];
sprite99 = [sheet99 createSpriteWithRect:CGRectMake(0,0,300,400)];//32 * idx,32 * idy,32,32
sprite99.position=ccp(4,14);
[sheet99 addChild:sprite99 z:7];




CCAnimation *animation = [CCAnimation animationWithName:@"dance" delay:.1f ];

[animation addFrameWithTexture:sheet99.texture rect:CGRectMake(-121,0,242,400)];//-121
[animation addFrameWithTexture:sheet99.texture rect:CGRectMake(0, 0, 242,400)];//0,0
id action = [CCAnimate actionWithAnimation:animation];
// Run the animation
//id repeatAction = [CCRepeat actionWithAction:action times:100];

// To repeat forever, use this
id repeatAction = [CCRepeatForever actionWithAction:action];

[sprite99 runAction:repeatAction];

No comments:

FEEDJIT Live