我知道你可以通过在游戏开始时创建精灵节点来预加载精灵节点,但是有没有更有效的方法呢?
问问题
684 次
1 回答
5
请参阅关于预加载纹理的 SKTexture 部分。
创建 SKTexture 而不是 SKSpriteNode。然后你可以使用 ether preloadWithCompletionHandler:或类方法preloadTextures:withCompletionHandler:
处理预加载的一个好方法是使用纹理图集。通过使用纹理图集,您可以将所有纹理组合成一个更大的“表”,其中包含所有这些。这允许 Sprite Kit 只创建一个纹理对象以加载到 VRAM 中。因为它只显示精灵表的一部分,所以图集中的所有纹理都可以在 GPU 的每次通过时绘制到屏幕上。
这是我使用 preloadWithCompletionHandler: 方法预加载纹理的方法:
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
// Preload the textures
self.artAtlas = [SKTextureAtlas atlasNamed:@"art"];
[self.artAtlas preloadWithCompletionHandler:^{
// Textures loaded so we are good to go!
/* Pick a size for the scene
Start with the current main display size.
*/
NSInteger width = [[NSScreen mainScreen] frame].size.width;
NSInteger height = [[NSScreen mainScreen] frame].size.height;
JRWTitleScene *scene = [JRWTitleScene sceneWithSize:CGSizeMake(width, height)];
/* Set the scale mode to scale to fit the window */
scene.scaleMode = SKSceneScaleModeAspectFit;
[self.skView presentScene:scene];
}];
#if DEBUG
self.skView.showsFPS = YES;
self.skView.showsNodeCount = YES;
#endif
}
在Sprite Kit Programming Guide的相关部分中有更多关于预加载纹理的信息。
于 2014-02-05T07:12:25.257 回答