我如何改变CCArray类型SpriteFrame

how to I change CCArray type to SpriteFrame?

本文关键字:CCArray 类型 SpriteFrame 改变 何改变      更新时间:2023-10-16

错误在

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

这一行,当我试图传递CCArray zoewalkingFrames到ccanimation_runanimm,日志说"引用类型'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;
}

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

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