1
的Cocos2D兩個動畫動畫我我的性格像:一個精靈
-(void) createHero
{
_batchNode = [CCSpriteBatchNode batchNodeWithFile:@"Snipe1.png"];
[self addChild:_batchNode];
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"Snipe1.plist"];
//gather list of frames
NSMutableArray *runAnimFrames = [NSMutableArray array];
for(int i = 1; i <= 7; ++i)
{
[runAnimFrames addObject:
[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:
[NSString stringWithFormat:@"run000%d.png", i]]];
}
//create sprite and run the hero
self.hero = [CCSprite spriteWithSpriteFrameName:@"run0001.png"];
_hero.anchorPoint = CGPointZero;
_hero.position = self.heroRunningPosition;
//create the animation object
CCAnimation *runAnim = [CCAnimation animationWithFrames:runAnimFrames delay:1/30.0f];
self.runAction = [CCRepeatForever actionWithAction: [CCAnimate actionWithAnimation:runAnim restoreOriginalFrame:YES]];
[_hero runAction:_runAction];
[_batchNode addChild:_hero z:0];
}
這工作得很好了我的性格正在運行,但現在我想第二個動畫,當他跳躍。目前,我讓這樣的:
-(void)changeHeroImageDuringJump
{
[_hero setTextureRect:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:@"run0007.png"].rect];
}
但現在我想用第二PNG第二的plist,所以我得到了一個全新的動畫當角色跳躍。我怎樣才能實現呢?
我在你的項目中添加了你的兩個類,但是我不知道你如何實現他們我有Snipe1.plist Snipe2.plist和Snipe1.png和Snipe2.png。在plist中有run0001-run0007.png,在Snipe2中是jump0001-jump0007.png。我現在如何添加這兩個動畫?感謝您的回答 ! – dehlen 2012-07-19 16:29:41
哦,什麼是AKHelpers?我在哪裏可以得到這個? – dehlen 2012-07-19 16:40:17
你可以在這裏找到AKHelpers,http://www.cocos2d-iphone.org/forum/topic/13851,它有它自己的動畫plist格式。你所做的基本上是一個將引用紋理和座標的plist,然後定義幀和持續時間。你可以讓你的plist類似於這裏找到的示例:https://github.com/anton-nikan/iOS-Animation-Kit/blob/master/Samples/cocos2d/frog-menu-anim.plist – 2012-07-19 16:59:25