我目前正在用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