关于执行一段帧动画

我是初学者…下载了最新的那个cocos2dx来学习…
然后网上大多数教程都是2.0之前的…
所以现在貌似网上的代码都用不了…所以特来此请救!

CCArray *arrayFrames = new CCArray(4);

CCSpriteFrame *frame1 = cache->spriteFrameByName("girl1.png");
CCAnimationFrame *animationFrame1 = new CCAnimationFrame();
animationFrame1->setSpriteFrame(frame1);
arrayFrames->addObject(animationFrame1);
animationFrame1->release();

CCSpriteFrame *frame2 = cache->spriteFrameByName("girl2.png");
CCAnimationFrame *animationFrame2 = new CCAnimationFrame();
animationFrame2->setSpriteFrame(frame2);
arrayFrames->addObject(animationFrame2);
animationFrame2->release();

CCSpriteFrame *frame3 = cache->spriteFrameByName("girl3.png");
CCAnimationFrame *animationFrame3 = new CCAnimationFrame();
animationFrame3->setSpriteFrame(frame3);
arrayFrames->addObject(animationFrame3);
animationFrame3->release();

CCSpriteFrame *frame4 = cache->spriteFrameByName("girl4.png");
CCAnimationFrame *animationFrame4 = new CCAnimationFrame();
animationFrame4->setSpriteFrame(frame4);
arrayFrames->addObject(animationFrame4);
animationFrame4->release();

CCAnimation *animation = CCAnimation::create(arrayFrames, 1,2);

CCSprite *sprite = CCSprite::createWithSpriteFrameName("girl2.png");
sprite->setPosition(ccp(size.width*0.4, size.height*0.4));
spriteBatch->addChild(sprite);
sprite->runAction(CCAnimate::create(animation));

请问有没有人能解答一下…为什么我运行不起来

从plist 读文件
//=============================================================
CCAnimate* CCAPI::getAnimateFromPlist(const char* szBaseName,float fDelayTime)
{
char listName = {0};
sprintf(listName, “%s.plist”, szBaseName);

CCSpriteFrameCache *frameCache = CCSpriteFrameCache::sharedSpriteFrameCache();
assert(frameCache);
frameCache->addSpriteFramesWithFile(listName);

CCArray animFrames;
char str = {0};
while(1)
{
    sprintf(str,"%s_%02d.png", szBaseName, animFrames.count() + 1);
    CCSpriteFrame* frame = frameCache->spriteFrameByName(str);
    if(!frame)
    {
        break;
    }
    else
    {
        animFrames.addObject(frame);
    }
}
CCAnimation* animation = CCAnimation::create(&animFrames,fDelayTime);
CCAnimate* animate = CCAnimate::create(animation);
return animate;

}
//=============================================================

读散文件
//=============================================================
CCAnimate* CCAPI::getAnimate(const char* szBaseName,float fDelayTime,int nCount)
{
CCSpriteFrameCache *frameCache = CCSpriteFrameCache::sharedSpriteFrameCache();
assert(frameCache);

CCArray* pAnimFrames = CCArray::create();
char str = {0};
for(int i=1;i<=nCount;i++)
{
    sprintf(str,"%s_%02d.png", szBaseName,i);
    CCSprite* pSprite = CCSprite::create(str);
    if(!pSprite)
    {
        break;
    }
    CCSize contentSize = pSprite->getContentSize();
    CCSpriteFrame* frame = CCSpriteFrame::createWithTexture(pSprite->getTexture(), CCRectMake(0, 0, contentSize.width, contentSize.height));
    pAnimFrames->addObject(frame);
}
CCAnimation* animation = CCAnimation::createWithSpriteFrames(pAnimFrames,fDelayTime);
CCAnimate* animate = CCAnimate::create(animation);
return animate;

}

关于这类问题,建议楼主最好先熟悉认真仔细的看下 DEMO :TestCPP ,保管你收获不小。你对照着做,就木有问题了,啥问题都解决了…这个DEMO,能帮助你搞定很多事情

— Begin quote from ____

樱木vs鸣人 发表于 2013-5-9 17:17 url

关于这类问题,建议楼主最好先熟悉认真仔细的看下 DEMO :TestCPP ,保管你收获不小。你对照着做,就木有问 …

— End quote

en!谢了,最近这几天比较忙…现在有时间了,我正在看!你不说…我还真的不知道里面还有一个testcpp的东西

— Begin quote from ____

bingwan 发表于 2013-5-11 23:44 url

从plist 读文件
//=============================================================
CCAnimate* CCAPI::ge …

— End quote

我回去试一下你写的代码…看看有没有问题先!