这个游戏打算是用C#+GDI做~所以渲染效率上还是要进行一些考虑的
这里对传统的GDI+封装了下,通过批处理来提高一些效率
首先给出的是渲染接口的定义,方面以后更换高性能的渲染器(当然很遥远)
/// <summary>
/// 渲染器接口
/// </summary>
public interface IRenderHandler
{
void Clear(Color backgroundColor);
void DrawLine(int x1, int y1, int x2, int y2, Color color);
void DrawBox(int x, int y, int width, int height, Color color, bool fill);
void DrawImage(int destX, int destY, int destWidth, int destHeight, Bitmap source, int sourceX, int sourceY, int sourceWidth, int sourceHeight);
object GetSurface();
}
这是实现一个渲染器需要实现的接口,大体上就这么多
然后是用GDI实现的一个渲染器
/// <summary>
/// GDI渲染器
/// </summary>
public class GDIRender : IRenderHandler
{
private Bitmap mSurface;
private Graphics mG;
public GDIRender(int width, int height)
{
mSurface = new Bitmap(width, height);
mG = Graphics.FromImage(mSurface);
}
public void Clear(Color backgroundColor)
{
mG.Clear(backgroundColor);
}
public void DrawLine(int x1, int y1, int x2, int y2, Color color)
{
mG.DrawLine(new Pen(color), x1, y1, x2, y2);
}
public void DrawBox(int x, int y, int width,