38f1ddb...178a853: v0.8.9.1, removed content folder
This commit is contained in:
@@ -4,35 +4,55 @@ using System.Xml.Linq;
|
||||
|
||||
namespace Barotrauma
|
||||
{
|
||||
partial class SpriteSheet : Sprite
|
||||
public partial class SpriteSheet : Sprite
|
||||
{
|
||||
private Rectangle[] sourceRects;
|
||||
private int emptyFrames;
|
||||
|
||||
public int FrameCount
|
||||
{
|
||||
get { return sourceRects.Length; }
|
||||
get { return sourceRects.Length - emptyFrames; }
|
||||
}
|
||||
|
||||
public Point FrameSize
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public SpriteSheet(XElement element, string path = "", string file = "")
|
||||
public SpriteSheet(XElement element, string path = "", string file = "", int emptyFrameCount = 0)
|
||||
: base(element, path, file)
|
||||
{
|
||||
int columnCount = Math.Max(element.GetAttributeInt("columns", 1), 1);
|
||||
int rowCount = Math.Max(element.GetAttributeInt("rows", 1), 1);
|
||||
origin = element.GetAttributeVector2("origin", new Vector2(0.5f, 0.5f));
|
||||
emptyFrames = emptyFrameCount;
|
||||
Init(columnCount, rowCount);
|
||||
}
|
||||
|
||||
public SpriteSheet(string filePath, int columnCount, int rowCount, Vector2 origin)
|
||||
: base(filePath, origin)
|
||||
{
|
||||
this.origin = origin;
|
||||
Init(columnCount, rowCount);
|
||||
}
|
||||
|
||||
private void Init(int columnCount, int rowCount)
|
||||
{
|
||||
sourceRects = new Rectangle[rowCount * columnCount];
|
||||
|
||||
int cellWidth = SourceRect.Width / columnCount;
|
||||
int cellHeight = SourceRect.Height / rowCount;
|
||||
float cellWidth = SourceRect.Width / columnCount;
|
||||
float cellHeight = SourceRect.Height / rowCount;
|
||||
FrameSize = new Point((int)cellWidth, (int)cellHeight);
|
||||
|
||||
for (int x = 0; x < columnCount; x++)
|
||||
{
|
||||
for (int y = 0; y < rowCount; y++)
|
||||
{
|
||||
sourceRects[x + y * columnCount] = new Rectangle(x * cellWidth, y * cellHeight, cellWidth, cellHeight);
|
||||
sourceRects[x + y * columnCount] = new Rectangle((int)(SourceRect.X + x * cellWidth), (int)(SourceRect.Y + y * cellHeight), (int)cellWidth, (int)cellHeight);
|
||||
}
|
||||
}
|
||||
|
||||
origin = element.GetAttributeVector2("origin", new Vector2(0.5f, 0.5f));
|
||||
origin.X = origin.X * cellWidth;
|
||||
origin.Y = origin.Y * cellHeight;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user