实现资源预加载时,怎么获取csb中对应的plist文件啊?求大神解救啊!!!
auto pNode = CSLoader::createNode("*.csb");
pNode->setPosition(Vec2::ZERO);
auto sprite = static_cast(pNode->getChildByName("SpriteName"));
```
SpriteName指的是你使用.plist创建的精灵的名称
通过csb文件创建node没问题的,现在主要是想通过解析csb文件,获取里面关联的plist的文件,进行预加载
你在csb中使用了plist文件创造序列帧动画吗?
不是的,我是把csb使用的资源全部做成大图了,在预加载的时候,提前加载csb中的plist与png大图
意思就是说你只是把所有图合图了,但是在csb中并未使用,是吧。那你使用plist和png和csb是无关的。
// ①创建缓存,将图片读取进来
auto cache = SpriteFrameCache::sharedSpriteFrameCache();
cache -> addSpriteFramesWithFile("roleanimate/1001_role.plist", "roleanimate/1001_role.png");
// ②创建第一帧,设置位置,加入到当前场景
auto sp = CCSprite::createWithSpriteFrameName("1001_role/0000");
sp -> setPosition(Point(visibleSize.width/3,visibleSize.height/2));
this -> addChild( sp );
Vector< SpriteFrame* > sfme = Vector< SpriteFrame* >::Vector();
char str = {0};
for( int i = 1 ; i < 4 ; ++i )
{
// ④ 获取图片名字,加入到集合中
sprintf(str,"1001_role/%04d",i);
SpriteFrame *fname = cache -> spriteFrameByName( str );
sfme.pushBack( fname );
}
// ⑤ 创建动画,设置播放速度
auto animation = CCAnimation::createWithSpriteFrames( sfme , 0.1f );
sp -> runAction ( CCRepeatForever::create(CCAnimate::create(animation )));
```
以上代码就是使用plist和png制作动画的,你只要把我的关于图片的参数换成你自己的就行
如果楼主是想要使用plist和png制作场景,那么直接使用cocos studio进行制作就行,使用时只需要加载csb就行了
楼主找到办法了吗?我最近也在想这个问题,如果有解决办法了麻烦共享一下!
终于找到一种方法了:
std::string fullPath = FileUtils::getInstance()->fullPathForFilename(“effect/ut00001.csb”);
Data buf = FileUtils::getInstance()->getDataFromFile(fullPath);
auto fileDataBytes = buf.getBytes();
auto fileDataSize = buf.getSize();
auto csparsebinary = GetCSParseBinary(buf.getBytes());
auto textures = csparsebinary->textures();
int textureSize = csparsebinary->textures()->size();
vector<std::string> stListArr;
for (int i = 0; i < textureSize; ++i){
CCLOG("texture name = %s", textures->Get(i)->c_str());
vector<std::string>::iterator result = std::find(stListArr.begin(), stListArr.end(), textures->Get(i)->c_str());
if (result == stListArr.end()){
stListArr.push_back(textures->Get(i)->c_str());
}
}
stListArr:存放plist文件名
我cocos3.2 + studio 1.6用过类似的方式自己解析json文件,后面因为效率问题弃用了,改成自己手动加载用到的plist。
是怎么预加载csb的