加载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"];

你可能感兴趣的:(xcode,Scene,CCB,SpriteBuil,ccbi)