0

我一直在尝试为具有不同帧的精灵设置动画,但没有成功。什么都没发生。我有 12 张图片(loading1.png 到 loading12.png)。

我怎样才能为它制作动画?这是我的代码

CCAnimation animation = CCAnimation.animation("frameanimation", 2.0f);
    for(int i = 0; i < 12; i++){
        animation.addFrame(CCSpriteFrameCache.sharedSpriteFrameCache().spriteFrameByName("gfx/loading/loading" + (i + 1) + ".png"));
    }
    CCAction action = CCAnimate.action(2.0f, animation, true);
    this.runAction(action);
4

1 回答 1

0

使用您的图像(loading1.png 到 loading12.png)使用 TexturePacker 制作纹理,这将生成纹理文件和数据(plist)文件。然后按照以下步骤操作:

CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile(plistFile);
CCSpriteBatchNode* batchNode = CCSpriteBatchNode::create(pngTextureFile);
this->addChild(batchNode);
 CCSprite* sprite = CCSprite::createWithSpriteFrameName("first_frame_name");
 CCArray* frames = new CCArray;
 frames->initWithCapacity(frameCount);
 for (int i = 1; i < frameCount; i++) {
        CCString* frameName = CCString::createWithFormat("1-%d.png",i);
        frames->addObject(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(frameName->getCString()));
    }

 CCAnimation* animation = new CCAnimation;
 bool isLoaded = animation->initWithSpriteFrames(frames);
 sprite->runAction(CCAnimate::create(animation));
 batchNode->addChild(sprite);
于 2013-10-30T05:47:02.420 回答