• GDI+ 小破孩动画


    无聊写个动画程序,GDI+ 双缓存,无法去除背景色,不知道为什么?

    知道的,麻烦告诉我一下

    代码
     1 namespace Animation
     2 {
     3     public partial class Form1 : Form
     4     {
     5         private Rectangle drawArea;
     6         private Bitmap currentShape;
     7         private static Graphics buffScreenGraphics, onScreenGraphics;
     8         private static int currentShapeIndex = 0;
     9         private static Bitmap buffScreenBitmap;
    10 
    11         public Form1()
    12         {
    13             InitializeComponent();
    14             Init();
    15         }
    16 
    17         private void Init()
    18         {
    19             this.Visible = true;
    20             drawArea = new Rectangle(00150130);
    21             onScreenGraphics = this.CreateGraphics();
    22             buffScreenBitmap = new Bitmap(drawArea.Width, drawArea.Height);
    23             buffScreenGraphics = Graphics.FromImage(buffScreenBitmap);
    24             buffScreenGraphics.Clear(Color.Green);
    25 
    26             SpriteList.Instance.LoadSprites();
    27 
    28             currentShape = SpriteList.Instance.Sprites[currentShapeIndex];
    29             buffScreenGraphics.DrawImage(currentShape,0,0,currentShape.Width,currentShape.Height);
    30         }
    31 
    32         protected override void  OnPaint(PaintEventArgs e)
    33         {
    34             onScreenGraphics.DrawImage(buffScreenBitmap, drawArea);
    35              base.OnPaint(e);
    36         }
    37 
    38         private void ReDraw()
    39         {
    40             onScreenGraphics.DrawImage(buffScreenBitmap, drawArea);
    41         }
    42 
    43         private void DoNextShape()
    44         {
    45             currentShapeIndex = currentShapeIndex == 7 ? 0 : currentShapeIndex + 1;
    46             buffScreenBitmap = SpriteList.Instance.Sprites[currentShapeIndex];
    47         }
    48 
    49         private void timer1_Tick(object sender, EventArgs e)
    50         {
    51             DoNextShape();
    52             ReDraw();
    53             this.Left -= 10;
    54              if (this.Left < -this.Width)
    55                  this.Left = Screen.PrimaryScreen.Bounds.Width;
    56         }
    57 
    58         private void Form1_KeyPress(object sender, KeyPressEventArgs e)
    59         {
    60              if (e.KeyChar == 27)
    61                  this.Dispose();
    62         }
    63     }
    64 }

    源文件

  • 相关阅读:
    重写不受限制
    类的向上转型(安全)向下转型(不安全)
    类的继承之构造函数和析构函数的顺序
    父类和子类的截断现象
    派生类重写方法
    运算符重载总结(大全)
    运算符重载方法3
    运算符重载方法2
    Shell基础编程
    TCP Wrappers(简单防火墙)---限制IP登录ssh
  • 原文地址:https://www.cnblogs.com/Kurodo/p/1444950.html
Copyright © 2020-2023  润新知