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( 0 0 150 130 );
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  }

 

 

源文件

你可能感兴趣的:(DI)