Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- XNA Texture2D caching
- public class ContentCache
- {
- private readonly ContentManager _content;
- private readonly Dictionary<string, Texture2D> _textureCache = new Dictionary<string, Texture2D>();
- public ContentCache(ContentManager content)
- {
- _content = content;
- }
- public Texture2D Load(string assetName)
- {
- Texture2D texture = null;
- if (!_textureCache.TryGetValue(assetName, out texture))
- {
- _textureCache[assetName] =
- texture = _content.Load<Texture2D>(assetName);
- }
- return texture;
- }
- }
- // Preload assets
- static readonly string[] preloadAssets =
- {
- "Textures\texture1",
- };
- protected override void LoadContent()
- {
- foreach ( string asset in preloadAssets )
- {
- Content.Load<object>(asset);
- }
- }
Add Comment
Please, Sign In to add comment