-
Notifications
You must be signed in to change notification settings - Fork 1
/
TextureAtlas.cs
39 lines (33 loc) · 1.11 KB
/
TextureAtlas.cs
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
31
32
33
34
35
36
37
38
39
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
namespace ClaimTheCastle
{
class TextureAtlas
{
#region Properties
public Texture2D Texture { get; }
public int TileWidth { get; }
public int TileHeight { get; }
public int TilesWide { get; }
public int TilesHigh { get; }
#endregion
public Rectangle[] SourceRectangles { get; }
public TextureAtlas(Texture2D image, int tilesWide, int tilesHigh, int tileWidth, int tileHeight)
{
Texture = image;
TileWidth = tileWidth;
TileHeight = tileHeight;
TilesWide = tilesWide;
TilesHigh = tilesHigh;
var tiles = tilesWide * tilesHigh;
SourceRectangles = new Rectangle[tiles];
var tile = 0;
for (int y = 0; y < tilesHigh; y++)
for (int x = 0; x < tilesWide; x++)
{
SourceRectangles[tile] = new Rectangle(x * tileWidth, y * tileHeight, tileWidth, tileHeight);
tile++;
}
}
}
}