私はWinformsアプリに取り組んでおり、アドバイスが必要です。
時間の経過とともに 2000x2000 の競技場を動き回る 50x50 のスプライトが数百個あります。最初は、フォームに追加されて動き回る、プログラム的に生成された画像ボックスであるスプライトを使用して作成しました。仕事は完了しましたが、ちらつきと遅さがありました。
かなりのグーグル検索の後、フレーム バッファを作成してそこに直接描画し、そのバッファをフォーム上の静止画像ボックスに適用する方法のように見えました。
だから私はこれをすべて装備し、ピクチャボックスを使用するよりもはるかに遅くなります. 2000x2000のバッファのサイズによるものと思われます(毎回バッファを作成するのに約100msかかります。)
画面を描画するためのコード:
private void animateAmoebas()
{
for (int animationStep = 0; animationStep < 100; animationStep = animationStep + animationStepSize)
{
Image buffer = new Bitmap(2000, 2000);
buffer = imageBKG; //Redraw the grid pattern.
foreach (Amoeba _Amoeba in amoebaPool)//Ameboa is a class object that has AI in it to detirmine the actions of the Amoeba.
{
//PBL (PictureBoxLoader) is an object that contains the sprite image, plus the cordinates for that sprite in that frame.
pbl = _Amoeba.animateSprite(animationStep,pbl);
drawSprite(pbl, buffer);//Draw the sprite to the buffer
}
refreshScreen(buffer);//Copy the buffer to the picturebox
}
}
private void drawSprite(PictureBoxLoader pbLoader, Image _buffer)
{
using (Graphics formGraphics = Graphics.FromImage(_buffer))
{
Point imgPoint = new Point(pbLoader.imgX, pbLoader.imgY);
formGraphics.DrawImageUnscaled(pbLoader.imgImage, imgPoint);
}
}
private void refreshScreen(Image _image)
{
pictureBox_BKG.Image = _image;
this.Refresh();
}
これを行うためのより良い方法についての提案はありますか?
事前にイメージバッファを作成し、背景を再描画するだけのスタティックを試してみました。これは役に立ちますが、ピクチャ ボックスを使用するよりも劇的に遅くなります。ただし、確かに上記の方法で適切な透明度が得られます。