0
嗨,我有面板异步绘图的问题。如果我没有清除它的作品,但清晰,它一直闪烁。我在主循环中创建窗体和面板,但我想绘制游戏循环。我的问题是如何在没有闪烁的情况下在图形面板上绘图F#闪烁createGraphics
let rec gameLoop (gamePanel:Panel) (lastTime:int64) (ball:Ball) = async {
lock gamePanel (fun() ->
if gamePanel.IsDisposed || close then
()
else
let rectangle = new System.Drawing.Rectangle(100, 100, 200, 200);
use graphics = gamePanel.CreateGraphics();
graphics.Clear(Color.White) (* when i use this it flickers *)
graphics.DrawEllipse(System.Drawing.Pens.Black, rectangle);
graphics.FillEllipse(ball.brush(), ball.rectangle());
)
return! gameLoop gamePanel (lastTime) (ball.move())
}
编辑x2。闪烁仍然存在,但也许我很好的方式
type PanelF() as this=
inherit Panel()
do this.DoubleBuffered <- true
member this.setStyle(a,b) = this.SetStyle(a, b)
编辑x3。我加入System.Threading.Thread.Sleep(30),它工作得更好,但仍然没有完全是我想要的
它不工作 – Luffy
@Luffy - 你看过我雁 - 你需要把'这一点。 doublebuffered < - true'在构造函数中,而不是成员。 –
我无法在构造函数中设置它。我得到了无效的表达。 new()= {inherit Panel(); this.DoubleBUffered < - true} – Luffy