加载SpriteBuilder中的scene为何不能带后缀

简介:

我们在Xcode中切换SpriteBuilder中的scene时,一般使用的是如下代码:

-(void)exitButtonPressed:(CCControl*)sender{
    CCLOG(@"Get me outa here!");
    CCLOG(@"sender is %@",sender);

    CCScene *scene = [CCBReader loadAsScene:@"MainScene"];

    CCTransition *transition = [CCTransition transitionCrossFadeWithDuration:1.5];
    [[CCDirector sharedDirector]presentScene:scene withTransition:transition];
}

但是实际我们知道MainScene是放在SpriteBuilder中的MainScen.ccb文件中的,我们能否在代码中加后缀调用呢?答案是:不可以!

原文引用如下:

“You should not append the .ccb file extension when loading CCBs. It’s a common and understandable mistake, but CCBReader will fail to load files where you specify the .ccb extension. Published CCB files are converted to a binary format optimized for fast loading and compact storage. This binary file format carries the extension .ccbi—that’s .ccb with a trailing i. The plain text format .ccb files aren’t actually in the bundle. Therefore, it’s important to omit the file extension in calls to CCBReader. Or, perhaps to remind you of the differing extensions, you can also append the .ccbi extension.”

原来SpriteBuilder中的ccb文件为了空间和格式的需求实际被转换为ccbi文件放在bundle中,这就是原因.

但是我们可以明确加载后缀为ccbi的文件,这样是可以的:

//that's all right!!!
CCScene *scene = [CCBReader loadAsScene:@"MainScene.ccbi"];
相关文章
|
12月前
Magisk模块:Scene附加模块(二)修改版
Magisk模块:Scene附加模块(二)修改版
2785 0
|
JavaScript
Vue 图片使用变量存放本地路径无法显示问题解决
Vue 图片使用变量存放本地路径无法显示问题解决
263 0
PyQt5 图形界面 - Qt Designer创建qrc资源文件引用图片资源实例演示,QTextBrower组件引用图片资源方法展示
PyQt5 图形界面 - Qt Designer创建qrc资源文件引用图片资源实例演示,QTextBrower组件引用图片资源方法展示
351 0
PyQt5 图形界面 - Qt Designer创建qrc资源文件引用图片资源实例演示,QTextBrower组件引用图片资源方法展示
PyQt5 技术篇-调用文件对话框获取文件、文件夹路径。文件对话框返回选中的多个文件路径
PyQt5 技术篇-调用文件对话框获取文件、文件夹路径。文件对话框返回选中的多个文件路径
2356 0
PyQt5 技术篇-调用文件对话框获取文件、文件夹路径。文件对话框返回选中的多个文件路径