KumiScript/renderer/Sprite.cs
2024-01-25 23:37:51 -06:00

56 lines
1.4 KiB
C#

using System.Text.Json.Serialization;
using KumiScript.Loader;
using SDL2;
namespace KumiScript.Renderer
{
public class Sprite : IDrawable
{
readonly SDLRenderer _renderer;
readonly Image _image;
SDL.SDL_Rect _drawCoords;
readonly int _height;
readonly int _width;
readonly int _xOffset;
readonly int _yOffset;
public Sprite(string path, SDLRenderer renderer)
{
_renderer = renderer;
_image = new Image(path, renderer);
KSMetaParser parser = new KSMetaParser(string.Concat(path, ".ksmeta"));
_height = parser.GetAttribute("height");
_width = parser.GetAttribute("width");
_xOffset = parser.GetAttribute("xOffset");
_yOffset = parser.GetAttribute("yOffset");
_drawCoords.w = _width;
_drawCoords.h = _height;
}
public void Draw(int x, int y)
{
_drawCoords.x = x + _xOffset;
_drawCoords.y = y + _yOffset;
SDL.SDL_RenderCopy(_renderer.id, _image.GetTexture().id, 0, ref _drawCoords);
}
public int GetBitmapHeight()
{
return _height;
}
public int GetBitmapWidth()
{
return _width;
}
public int GetXOffset()
{
return _xOffset;
}
public int GetYOffset()
{
return _yOffset;
}
}
}