Added texture cache and sprite origins.
This commit is contained in:
26
AlientAttack.MonoGame/Textures/TextureCache.cs
Normal file
26
AlientAttack.MonoGame/Textures/TextureCache.cs
Normal 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();
|
||||
}
|
||||
42
AlientAttack.MonoGame/Textures/TextureId.cs
Normal file
42
AlientAttack.MonoGame/Textures/TextureId.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AlienAttack.MonoGame.Textures;
|
||||
|
||||
//public enum TextureId
|
||||
//{
|
||||
// LaserBulletSmall,
|
||||
// LaserBulletMedium,
|
||||
// LaserBulletLarge,
|
||||
// MinigunBulletSmall,
|
||||
// LaserBulletMedium,
|
||||
// LaserBulletLarge,
|
||||
// LaserBulletSmall,
|
||||
// LaserBulletMedium,
|
||||
// LaserBulletLarge,
|
||||
// LaserBulletSmall,
|
||||
// LaserBulletMedium,
|
||||
// LaserBulletLarge,
|
||||
//}
|
||||
|
||||
public static class TextureNames
|
||||
{
|
||||
public static class Bullets
|
||||
{
|
||||
public const string LaserSmall = "Sprites/Laser_Small";
|
||||
public const string LaserMedium = "Sprites/Laser_Medium";
|
||||
public const string LaserLarge = "Sprites/Laser_Large";
|
||||
public const string MinigunSmall = "Sprites/Minigun_Small";
|
||||
public const string MinigunMedium = "Sprites/Minigun_Medium";
|
||||
public const string MinigunLarge = "Sprites/Minigun_Large";
|
||||
public const string PlasmaSmall = "Sprites/Plasma_Small";
|
||||
public const string PlasmaMedium = "Sprites/Plasma_Medium";
|
||||
public const string PlasmaLarge = "Sprites/Plasma_Large";
|
||||
public const string ProtonSmall = "Sprites/Proton_Small";
|
||||
public const string ProtonMedium = "Sprites/Proton_Medium";
|
||||
public const string ProtonLarge = "Sprites/Proton_Large";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user