ios - 我应该使用什么预加载 Sprite 的方法?

标签 ios sprite-kit skspritenode

关闭。这个问题需要更多 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/

相关文章:

iphone - 启动应用程序时的后台通知

ios - 如何不断地将数据从父 ViewController 发送到 Container View Controller

iphone - 重新加载时,UILabel 在 UITableViewCell 中不刷新

iphone - 发送 qLaunchSuccess 数据包失败

swift - swift 重复一个功能

swift - 如何停止'enumerateChildNodesWithName ("//*")'枚举?

swift - 触摸时向 SKSpriteNode 添加动画(Swift)

ios - 当敌人碰到相同颜色的玩家 Sprite 时,如何做出 Sprite Action ?

swift - SKSpriteNode 未加载到屏幕上?

arrays - 知道数组是否包含某种类型的元素