0

错误在于

CCAnimation *_runAnim = CCAnimation::createWithSpriteFrames(zoewalkingFrames, 0.1);

这条线,当我试图将 CCArray zoewalkingFrames 传递给 CCAnimation _runAnim 时,日志显示“对类型 'const Vector 的引用无法绑定到类型为 'CCArray' aka '”的左值,所以我应该怎么做才能做到将 CCArray var 传递给 SpriteFrame?谢谢

#include "ZoeAnime.h"
using namespace cocos2d;
bool ZoeAnime::init()
{
if ( !Node::init() )
{
    return false;
}

auto spritecache = SpriteFrameCache::getInstance();
spritecache->addSpriteFramesWithFile("zoeanime.plist");

CCSpriteBatchNode *_spritesheet = CCSpriteBatchNode::create("zoeanime.png");
this->addChild(_spritesheet);

CCArray* zoewalkingFrames = CCArray::create();
for(int i = 1; i <= 3; i++) {
    CCString* filename = CCString::createWithFormat("zoewalking%0d.png", i);
    CCSpriteFrame* frame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(filename->getCString());
    zoewalkingFrames->addObject(frame);
}

CCAnimation *_runAnim = CCAnimation::createWithSpriteFrames(zoewalkingFrames, 0.1);
CCSprite* zoe = CCSprite::createWithSpriteFrameName("zoewalking01.png");

CCSize winsize = CCDirector::sharedDirector()->getWinSize();
zoe->setPosition(ccp(winsize.width*0.5, winsize.height*0.5));

CCAction* action = CCRepeatForever::create(CCAnimate::create(_runAnim));

zoe->runAction(action);
_spritesheet->addChild(zoe);
return true;
}
4

1 回答 1

0

这是一个很好的参考,只需将 CCArray 替换为 Vector 数据类型。

http://discuss.cocos2d-x.org/t/erro-sprite-createwithspriteframes/16887

于 2015-07-31T17:15:59.800 回答