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 Background : SceneElement, IDisposable
|
|
{
|
|
SDLTexture _texture;
|
|
SDLRenderer _renderer;
|
|
int _height;
|
|
int _width;
|
|
int _anim;
|
|
int _frame;
|
|
|
|
public Background(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 = 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);
|
|
}
|
|
|
|
public override int GetBitmapHeight()
|
|
{
|
|
return 600;
|
|
}
|
|
|
|
public override int GetBitmapWidth()
|
|
{
|
|
return 800;
|
|
}
|
|
}
|
|
} |