-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathSpriteCache.cs
More file actions
30 lines (25 loc) · 741 Bytes
/
Copy pathSpriteCache.cs
File metadata and controls
30 lines (25 loc) · 741 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
using System.Collections.Generic;
using Microsoft.Xna.Framework.Graphics;
namespace Desktoptale
{
public class SpriteCache
{
private IDictionary<string, Texture2D> cache;
private GraphicsDevice graphicsDevice;
public SpriteCache(GraphicsDevice graphicsDevice)
{
this.graphicsDevice = graphicsDevice;
cache = new Dictionary<string, Texture2D>();
}
public Texture2D Get(string path)
{
if (cache.ContainsKey(path))
{
return cache[path];
}
Texture2D texture = Texture2D.FromFile(graphicsDevice, path);
cache.Add(path, texture);
return texture;
}
}
}