关闭。这个问题需要更多 focused .它目前不接受答案。
想改进这个问题?更新问题,使其仅关注一个问题 editing this post .
8年前关闭。
Improve this question
我知道你可以通过在游戏开始时创建 Sprite 节点来预加载 Sprite 节点,但是有没有更有效的方法呢?
最佳答案
请参阅 pre-loading textures 上的 SKTexture 部分.
创建 SKTexture 而不是 SKSpriteNode。
然后你可以使用以太 preloadWithCompletionHandler:或类方法preloadTextures:withCompletionHandler:
处理预加载的一个好方法是使用纹理图集。通过使用纹理图集,您可以将所有纹理组合成一个更大的“表”,其中包含所有这些。这允许 Sprite Kit 只创建一个纹理对象以加载到 VRAM 中。因为它只显示 Sprite 表的一部分,所以每次通过 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 的相关部分中有更多关于预加载纹理的信息。 .
关于ios - 我应该使用什么预加载 Sprite 的方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21567753/