私は現在、GDI+ でゲームを作成しています。ゲームを開発するための最適なソリューションではないことはわかっていますが、これは学校のプロジェクトであるため、選択の余地がありません。
ゲームを約 10 回実行するたびに、グラフィックが画面の左上隅のフォームの外側にレンダリングされます。
問題を絞り込むのに役立つ場合は、ダブルバッファリングを使用しています。
レンダリング コードは次のようになります。
while (true)
{
// Create buffer if it don't exist already
if (context == null)
{
context = BufferedGraphicsManager.Current;
this.buffer = context.Allocate(CreateGraphics(), this.DisplayRectangle);
}
// Clear the screen with the forms back color
this.buffer.Graphics.Clear(this.BackColor);
// Stuff is written to the buffer here, example of drawing a game object:
this.buffer.Graphics.DrawImage(
image: SpriteSheet,
destRect: new Rectangle(
this.Position.X
this.Position.Y
this.SpriteSheetSource.Width,
this.SpriteSheetSource.Height),
srcX: this.SpriteSheetSource.X,
srcY: this.SpriteSheetSource.Y,
srcWidth: this.SpriteSheetSource.Width,
srcHeight: this.SpriteSheetSource.Height,
srcUnit: GraphicsUnit.Pixel);
// Transfer buffer to display - aka back/front buffer swapping
this.buffer.Render();
}
スクリーンショットで説明する方が簡単です: