59 lines
No EOL
1.5 KiB
C#
59 lines
No EOL
1.5 KiB
C#
using KumiScript.Loader;
|
|
using SDL2;
|
|
|
|
namespace KumiScript.Renderer
|
|
{
|
|
public class Sprite : SceneElement, IDisposable
|
|
{
|
|
SDLTexture _texture;
|
|
SDLRenderer _renderer;
|
|
readonly int _height;
|
|
readonly int _width;
|
|
int _anim;
|
|
int _frame;
|
|
|
|
public Sprite(string path, SDLRenderer renderer)
|
|
{
|
|
_texture = new SDLTexture(path, renderer);
|
|
_renderer = renderer;
|
|
KSMetaParser parser = new KSMetaParser(string.Concat(path, ".ksmeta"));
|
|
_width = parser.GetAttribute("width");
|
|
_height = parser.GetAttribute("height");
|
|
_anim = 0;
|
|
_frame = 0;
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
_texture.Dispose();
|
|
return;
|
|
}
|
|
|
|
public override void Draw(int x, int y)
|
|
{
|
|
SDL.SDL_Rect destRect = new SDL.SDL_Rect();
|
|
destRect.x = x;
|
|
destRect.y = y;
|
|
destRect.w = _width;
|
|
destRect.h = _height;
|
|
|
|
SDL.SDL_Rect sourceRect = new SDL.SDL_Rect();
|
|
sourceRect.x = _anim * _width;
|
|
sourceRect.y = _frame * _height;
|
|
sourceRect.w = _width;
|
|
sourceRect.h = _height;
|
|
|
|
_texture.Draw(_renderer, sourceRect, destRect);
|
|
}
|
|
|
|
public override int GetBitmapHeight()
|
|
{
|
|
return _height;
|
|
}
|
|
|
|
public override int GetBitmapWidth()
|
|
{
|
|
return _width;
|
|
}
|
|
}
|
|
} |