简体   繁体   English

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

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

Would anyone please show me a small code sample written in C# within the Xamarin.iOS framework that would preload texture atlases ? 谁能给我看看Xamarin.iOS框架中用C#编写的可以预加载纹理图集的小代码示例吗?

Xamarin website has this page: Xamarin网站具有此页面:

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

On that webpage, they list the many methods that preload the texture atlases. 在该网页上,他们列出了许多预加载纹理图集的方法。 But, I am only interested in these 2 specific methods: 但是,我只对以下两种特定方法感兴趣:

PreloadTextures(SKTextureAtlas[], NSAction) PreloadTextures(SKTextureAtlas [],NSAction)

PreloadTexturesAsync(SKTextureAtlas[]) PreloadTexturesAsync(SKTextureAtlas [])

I guess both methods will work well for my game. 我猜这两种方法都适合我的游戏。 Unfortunately, I don't know how to properly call them in C# within the Xamarin.iOS framework. 不幸的是,我不知道如何在Xamarin.iOS框架内的C#中正确调用它们。

While there are many code samples for preloading texture atlases on the web, these samples are written in Objective-C, and, unfortunately, I don't know how to translate Objective-C code to C# code yet. 尽管网上有很多用于预加载纹理图集的代码示例,但是这些示例是用Objective-C编写的,但是,不幸的是,我还不知道如何将Objective-C代码转换为C#代码。

So, I would greatly appreciate if you could show me how to write some small code samples in C# within the Xamarin.iOS framework that preload texture atlases, using the 2 methods that I mentioned above. 因此,如果您能向我展示如何使用我上面提到的2种方法在Xamarin.iOS框架内用C#编写一些预加载纹理图集的小代码示例,将不胜感激。

Thank you very much. 非常感谢你。

I am not an expert on game development nor have i been involved in one before;however, I am reasonably familiar with the Xamarin.iOS to sort of "translate" the Objective-C codes to Xamarin C# codes. 我不是游戏开发专家,也没有参与过游戏;但是,我对Xamarin.iOS相当熟悉,可以将Objective-C代码“转换”为Xamarin C#代码。

First you need to create a "texture atlas" array 首先,您需要创建一个“纹理图集”数组

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()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM