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