Added texture cache and sprite origins.

This commit is contained in:
2026-01-14 23:09:13 -05:00
parent fcb4f1cf05
commit 61d51f5188
36 changed files with 319 additions and 83 deletions

View File

@@ -0,0 +1,26 @@
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();
}