3

我已经为一个角色创建了动画..需要帮助通过它的标签值将此动画添加到现有角色..到目前为止,我在网络上检查..所有人都在创建新CCSprite的来制作这个动画..但我需要它来添加这个动画到现有的 Sprite..existing Sprite 的标记值为 20.. 它在创建新的时动画效果很好..在CCSprite此先感谢..

CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("BearSprites.plist");
CCMutableArray<CCSpriteFrame*>* animateFrames = new CCMutableArray<CCSpriteFrame*>(9);
char str[50] = {0};
for(int i = 1; i < 9; i++)
{
    sprintf(str, "bear_frame%d.png",i);
    CCSpriteFrame *frame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(str);
    animateFrames->addObject(frame);
}
CCAnimation *animation = CCAnimation::animationWithFrames(animateFrames, 0.4f);
CCAnimationCache::sharedAnimationCache()->addAnimation(animation, "Walk");
CCAnimationCache *animCache = CCAnimationCache::sharedAnimationCache();
CCAnimation *normal = animCache->animationByName("Walk");
CCAnimate *animN = CCAnimate::actionWithAnimation(normal);
4

1 回答 1

2

使用此代码:

CCAnimate *animN = CCAnimate::actionWithAnimation(normal);
animN.tag = kTagHeroAnimation; //=272

CCSprite *sprite = (CCSprite*)[self getChildByTag:20];
[sprite stopActionByTag:kTagHeroAnimation]; //=272];
[sprite runAction: animN];
于 2013-04-04T11:43:42.593 回答