我目前正在用GDI +製作遊戲,我知道它不是開發遊戲的最佳解決方案,但由於它是一個學校項目,我別無選擇。圖形在GDI +外形下呈現+
大約每運行一次我的遊戲,圖形都會在屏幕左上角的窗體外呈現。
我正在使用雙緩衝,如果這有助於縮小問題。
渲染代碼如下所示:
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();
}
它很容易用截圖來解釋:
是直接渲染到窗體還是控件? –
什麼是'BufferedGraphicsManager'的樣子? – Ryan
它正在被渲染到窗體中,代碼被放置在從Form基類派生的類中。 – Lange