刷新时绘画刷新代码会闪烁

时间:2019-01-03 21:04:20

标签: c# flicker

我的游戏代码有一个绘画系统,在该系统中,每50个滴答声绘制一次绘画,然后重新绘制汽车(或盒子)。我在运行代码时(甚至当不移动时)的闪烁非常糟糕,我需要抓取其他任何东西:)

我尝试过: -双重缓冲 -将所有内容放入面板并刷新

//我的绘画代码

$str = "Server = YourServer; Database = YourDB; Integrated Security = True;"

$code = "ABC"
$date = (get-date).ToString("yyyy-MM-dd")
$execSript = "path\to\sqlExec.ps1"

# get a list of ids for code. You can achive the same with Invoke-sqlcmd or similar cmdlet.
 $conn = New-Object System.Data.SqlClient.SqlConnection $str
 $cmd = $conn.CreateCommand()
 $conn.Open()
 $cmd.CommandText = "select job_id, code from test.control_table where code = '$code'"
 $dt = New-Object System.Data.DataTable "result"
 $r = $cmd.ExecuteReader()
 $dt.Load($r)
 $conn.Close()

# main loop

$jobs = @{}

foreach($id in $dt.job_id) {  $top = $id*3

  $sql = "EXEC run_job $id, $date"

  $jobs.Add($id,(Start-Job -FilePath $execSript -ArgumentList $str, $sql))

}

# Wait for jobs and get result

$jobs.Values | Wait-Job | Receive-Job

我的计时器代码

            Bitmap greenCar = new 



            e.Graphics.FillRectangle(car.getDrawingbrushColor(), 
            car.getCarposition());
            e.Graphics.DrawImage(greenCar,car2.getCarposition());

    }

我的刷新代码

        scoreTimer.Tick += new EventHandler(Tick2);

        scoreTimer.Interval = 100;

        scoreTimer.Start();

        DoubleBuffered = true;

我只是不想让它闪烁,所以我真的阻止了我。

0 个答案:

没有答案