XNAs Content.Load<Texture2D>操作? [英] How does XNAs Content.Load<Texture2D> operate?

查看:36
本文介绍了XNAs Content.Load<Texture2D>操作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是很好奇它是否真的在每次调用时将资产加载到内存中,或者如果它查找它,发现它是否已加载,如果未加载,则加载一次,然后第二次保留引用它被称为它只是获取对它的引用?

I'm just curious if it actually loads the asset into memory every time it's called or if it looks it up, finds if it's loaded and if it isn't loaded it loads it once and just keeps references so the second time it's called it just grabs a reference to it?

推荐答案

它跟踪已加载的内容,如果之前已加载,则返回对同一对象的引用(这是每个 ContentManager).这适用于所有内容,而不仅仅是纹理.

It keeps track of what has already been loaded, and simply returns a reference to the same object if it has been loaded before (this is per-ContentManager). This applies to all content, not just textures.

结果是您可以在需要某些内容时调用 Load,而无需考虑重复.另一个结果是,您永远不应Dispose 从 ContentManager 加载的内容(改用 ContentManager.Unload).

The upshot is that you can just call Load whenever you need some Content, without having to think about duplication. The other upshot is that you should never Dispose of content loaded from ContentManager (use ContentManager.Unload instead).

如果你想了解更多细节,看看这个问答.

If you want more detail, take a look at this question and answer.

这篇关于XNAs Content.Load<Texture2D>操作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆