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 }

    源文件

  • 相关阅读:
    技术选型总结
    这些年来收集的好用的好玩的软件,强烈推荐给大家
    如何解决markdown中图片上传的问题
    01.如何把.py文件打包成为exe,重点讲解pyinstaller的用法
    Asp.net中汉字转换成为拼音
    程序员常用网址收集
    通过IP来判断所在城市
    以太坊
    分布式系统领域经典论文翻译集
    T50
  • 原文地址:https://www.cnblogs.com/Kurodo/p/1444950.html
Copyright © 2011-2022 走看看