基于C#弹幕类射击游戏的实现——(二)渲染

这个游戏打算是用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,
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值