zoukankan      html  css  js  c++  java
  • 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 }

    源文件

  • 相关阅读:
    Spring Cloud Bus 消息总线介绍
    工商银行分布式服务 C10K 场景解决方案
    关于写好文章的3个心法和5点技巧
    混合云K8s容器化应用弹性伸缩实战
    云原生下的灰度体系建设
    被解救的代码
    【2020-10-22】我是否一个真正靠谱的人
    【2020-10-21】以谦虚与忍耐去期待豁然与贯通
    【2020-10-20】压力也是一种感受,用心体会
    【2020-10-19】不断试错的过程
  • 原文地址:https://www.cnblogs.com/Kurodo/p/1444950.html
Copyright © 2011-2022 走看看