KumiScript/renderer/Background.cs

59 lines
1.5 KiB
C#
Raw Normal View History

using KumiScript.Loader;
2024-01-26 05:37:51 +00:00
using SDL2;
namespace KumiScript.Renderer
{
public class Background : SceneElement, IDisposable
2024-01-26 05:37:51 +00:00
{
SDLTexture _texture;
2024-01-26 05:37:51 +00:00
SDLRenderer _renderer;
int _height;
int _width;
int _anim;
int _frame;
2024-01-26 05:37:51 +00:00
public Background(string path, SDLRenderer renderer)
{
_texture = new SDLTexture(path, renderer);
2024-01-26 05:37:51 +00:00
_renderer = renderer;
KSMetaParser parser = new KSMetaParser(string.Concat(path, ".ksmeta"));
_width = parser.GetAttribute("width");
_height = parser.GetAttribute("height");
_anim = 0;
_frame = 0;
2024-01-26 05:37:51 +00:00
}
public void Dispose()
2024-01-26 05:37:51 +00:00
{
_texture.Dispose();
return;
2024-01-26 05:37:51 +00:00
}
public override void Draw(int x, int y)
2024-01-26 05:37:51 +00:00
{
SDL.SDL_Rect destRect = new SDL.SDL_Rect();
destRect.x = x;
destRect.y = y;
destRect.w = 800;
destRect.h = 600;
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);
2024-01-26 05:37:51 +00:00
}
public override int GetBitmapHeight()
2024-01-26 05:37:51 +00:00
{
return 600;
2024-01-26 05:37:51 +00:00
}
public override int GetBitmapWidth()
2024-01-26 05:37:51 +00:00
{
return 800;
2024-01-26 05:37:51 +00:00
}
}
}