如何将CCArray类型更改为SpriteFrame?

时间:2015-07-31 16:52:24

标签: c++ ios coco2d-x

错误在于

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

这一行,当我试图将CCArray zoewalkingFrames传递给CCAnimation _runAnim时,日志显示"引用类型' const Vector无法绑定到类型' CCArray&的左值#39; 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;
}

1 个答案:

答案 0 :(得分:0)

这是一个很好的参考,只需用矢量数据类型替换CCArray。

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