Download - ePrints
Transcript
4.1. ANIMATIONS IN RUN&ROLL
27
moving in the desired direction. The code snippet below shows how our
Hero’s animation was created, and the logic for angle and movement type
changes.
// Part 1: FrameAnimation.m
− (id)initWithAnimationName: (NSString ∗) animationName animationType:
(NSString ∗) type angle:( int )angle withNumberOfFrames: (int) frameCount
{
if (( self = [super init ]) ) {
self .isRepeating = YES;
self .animationName = animationName;
CCSpriteFrameCache ∗spriteCache = [CCSpriteFrameCache
sharedSpriteFrameCache];
NSString ∗plistFileName = [NSString stringWithFormat:@”%@.plist”,
animationName];
[spriteCache addSpriteFramesWithFile:plistFileName];
NSString ∗imageName = [NSString stringWithFormat:@”%@.png”, self.
animationName];
CCSpriteBatchNode ∗spriteSheet = [CCSpriteBatchNode batchNodeWithFile:
imageName];
self .animationType = type;
self .angle = angle;
NSString ∗currentFrameName = [NSString stringWithFormat: @”%@%@%i 0.
png”, self.animationName, self.animationType, self.angle];
self .frame = [CCSprite spriteWithSpriteFrameName: currentFrameName] ;
[ self addChild:self .frame];
self .currentFrame = 0;
self .frameCount = frameCount;
self . isPlaying = NO;
}
return self ;
}