2011-07-17 6 views
1

これは私がやろうとしていることです。私はSWFとSDネームスペースだけを使ってゲームを作っています。私は1000/30インターバル(30フレーム)のタイマーを使って、 InvokeGraphics()を呼び出すと、楕円が描かれていることを除いて、すべてが多少レンダリングされます。ダブルバッファリングとthis.SetStyle()を使用しようとしましたが失敗しました。コード:VC#Form Flickers

public partial class MainForm : Form 
{ 
    int x = 0; 
    public MainForm() 
    { 

     InitializeComponent(); 

     var sz = SystemInformation.PrimaryMonitorSize; 
     this.FormBorderStyle = FormBorderStyle.None; 
     this.Size = sz; 
     this.SetStyle(ControlStyles.OptimizedDoubleBuffer,true); 

     Timer tmr = new Timer(); 
     tmr.Enabled = true; 
     tmr.Interval = 1000/30; 
     tmr.Tick += delegate(object sender, EventArgs e) 
     { 
      x++; 
      this.InvokePaint(this,new PaintEventArgs(this.CreateGraphics(),this.Bounds)); 
     }; 
    } 
    protected override void OnKeyPress(KeyPressEventArgs e) 
    { 
     if((int)e.KeyChar == 27) Application.Exit(); 
     base.OnKeyPress(e); 
    } 
    protected override void OnPaint(PaintEventArgs e) 
    { 
     var g = e.Graphics; 

     g.Clear(Color.Firebrick); 
     // this ellipse flickrs 
     g.FillEllipse(Brushes.Green,x,64,64,64); 

     base.OnPaint(e); 
    } 
    protected override void OnMouseClick(MouseEventArgs e) 
    { 

     base.OnMouseClick(e); 
    } 

} 
+1

注:これは私の宿題ではありません。 –

答えて

5

this.CreateGraphics()はではありません。は、ダブルバッファのペインティングコンテキストを作成します。フォームのDoubleBufferedプロパティをtrueに設定します。また、32ミリ秒の間隔のタイマーを使用して強制的にリフレッシュし、そのTickイベントハンドラーでのみInvalidate()を呼び出します。

+1

ありがとうございます。 –