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 网关
    spring cloud 熔断器
    spring cloud 健康检查
    spring cloud 分布式链路跟踪(集成zipkin)
    spring cloud 分布式链路追踪
    spring cloud eureka 微服务之间的调用
    spring cloud eureka注册中心
    ACCP8.0Y2Web前端框架与移动应用开发第5章Bootstrap制作微票儿首页
    ACCP8.0Y2Web前端框架与移动应用开发第4章Bootstrap的JavaScript插件
    ACCP8.0Y2Web前端框架与移动应用开发第3章Bootstrap组件
  • 原文地址:https://www.cnblogs.com/Kurodo/p/1444950.html
Copyright © 2011-2022 走看看