简体   繁体   English

在 XNA 中加载纹理的最快方法是什么

[英]What is the fastest way to load Textures in XNA

I'm a student using the latest version of Microsoft XNA for learning purposes.我是一名学生,使用最新版本的 Microsoft XNA 进行学习。

I need to load a whole lot of texture from the Content folder (or more specifically a folder called Tiles inside the Content folder) and I really don't want to type the following code 100 times:我需要从 Content 文件夹(或者更具体地说是 Content 文件夹中名为 Tiles 的文件夹)加载大量纹理,我真的不想输入以下代码 100 次:

texture = Content.Load<Texture2D>("texture");

I realize I could change the names of the files and run through a loop to load them, but this seems inefficient for finding specific tiles if there's a way I could keep the names.我意识到我可以更改文件的名称并通过循环运行以加载它们,但是如果有办法可以保留名称,这对于查找特定的图块似乎效率低下。 I am just looking for a way to load all of these that saves development time.我只是在寻找一种方法来加载所有这些以节省开发时间。

Also, the files are in.BMP form, if that matters.此外,如果重要的话,这些文件是.BMP 格式的。

Keep in mind that every texture needs to be loaded at least once.请记住,每个纹理都需要至少加载一次。 So using所以使用

texture = Content.Load<Texture2D>("texture");

is fine to repeat for different textures, as long as you don't repeat it for the same texture.只要您不为相同的纹理重复它,就可以重复不同的纹理。

I've learned is to load all textures in the LoadContent() of game1.cs, that method is only called once at the moment the game starts.我学到的是在 game1.cs 的LoadContent()中加载所有纹理,该方法仅在游戏开始时调用一次。 So they're all ready to be used for the rest of the game.因此,它们都已准备好用于游戏的 rest。

There's also a Lazy Loading practice, where the texture is only loaded for when the object appears.还有一种延迟加载实践,仅在 object 出现时才加载纹理。 But you should be aware that the texture loading won't repeat itself for each object.但是您应该知道,纹理加载不会为每个 object 重复。

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

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