J'anime mon personnage comme ça:Cocos2d Deux animations pour un sprite
-(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];
}
Cela fonctionne bien un mon personnage est en cours d'exécution, mais maintenant je veux une deuxième animation quand il saute. En ce moment je fais comme ça:
-(void)changeHeroImageDuringJump
{
[_hero setTextureRect:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:@"run0007.png"].rect];
}
Mais maintenant, je veux une deuxième plist avec un deuxième .png, donc je reçois une nouvelle animation tout lorsque le personnage saute. Comment puis-je mettre en œuvre cela?
J'ai ajouté vos deux classes dans mon projet mais j'ai ne comprends pas comment vous les implémentez j'ai Snipe1.plist Snipe2.plist et Snipe1.png et Snipe2.png. Dans le plist, il y a run0001-run0007.png et dans Snipe2, jump0001-jump0007.png. Comment puis-je ajouter ces deux animations maintenant? Merci pour votre réponse ! – dehlen
Oh et qu'est ce que AKHelpers? Où puis-je obtenir ceci? – dehlen
Vous pouvez trouver AKHelpers ici, http://www.cocos2d-iphone.org/forum/topic/13851, il a son propre format de plist pour les animations. Ce que vous faites est fondamentalement une plist qui référencera à la fois la texture et les coordonnées, puis définira les cadres et la durée. Vous pouvez faire votre plist semblable à l'échantillon trouvé ici: https://github.com/anton-nikan/iOS-Animation-Kit/blob/master/Samples/cocos2d/frog-menu-anim.plist –