Files

26 lines
688 B
C#

using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using System.Collections.Generic;
namespace AlienAttack.MonoGame.Textures;
public sealed class TextureCache
{
private readonly Dictionary<string, Texture2D> _cache = [];
private ContentManager _content = default!;
public void Initialize(ContentManager content) => _content = content;
public Texture2D Get(string assetName)
{
if (_cache.TryGetValue(assetName, out var texture))
return texture;
texture = _content.Load<Texture2D>(assetName);
_cache[assetName] = texture;
return texture;
}
public void Clear() => _cache.Clear();
}