如何在 Xamarin.iOS 中预加载纹理图集 (SKTextureAtlas)(在 C# 中)?

How to preload texture atlas (SKTextureAtlas) in Xamarin.iOS (in C#)?

谁能给我看一个在 Xamarin.iOS 框架内用 C# 编写的预加载纹理图集的小代码示例?

Xamarin 网站有这个页面:

https://developer.xamarin.com/api/type/MonoTouch.SpriteKit.SKTextureAtlas/

在该网页上,他们列出了许多预加载纹理图集的方法。但是,我只对这两种具体方法感兴趣:

PreloadTextures(SKTextureAtlas[], NSAction)

PreloadTexturesAsync(SKTextureAtlas[])

我想这两种方法都适合我的游戏。不幸的是,我不知道如何在 Xamarin.iOS 框架内用 C# 正确调用它们。

虽然网上有很多预加载纹理图集的代码示例,但这些示例是用 Objective-C 编写的,不幸的是,我不知道如何将 Objective-C 代码翻译成 C#代码还没有。

因此,如果您能告诉我如何使用我上面提到的 2 种方法在预加载纹理图集的 Xamarin.iOS 框架内用 C# 编写一些小代码示例,我将不胜感激。

非常感谢。

我不是游戏开发专家,之前也没有参与过;但是,我相当熟悉 Xamarin.iOS "translate" Objective-C 代码到 Xamarin C# 代码。

首先你需要创建一个"texture atlas"数组

var textureCollection = new SKTextureAtlas[]
{
    SKTextureAtlas.FromName("firsttexturename"),
    SKTextureAtlas.FromName("secondtexturename"),
};
await SKTextureAtlas.PreloadTexturesAsync(textureCollection);
// rather than using a completion handler like in ObjC xamarin uses the c# 5's await keyword to achieve similar functions
//You can do what you want after it has preloaded here 
//for example
this.StartScene()