0

我正在尝试声明新的抽象类

using System;
using System.Drawing;
using System.Windows.Forms;
using Microsoft.Xna.Framework.Graphics;
abstract public class GraphicsDeviceControl : Control
{
    //....

    protected abstract void Update();

}

但是当我编译它时,我收到了这个警告:

“WinFormsContentLoading.GraphicsDeviceControl.Update()”隐藏了继承的成员“System.Windows.Forms.Control.Update()”。如果打算隐藏,请使用 new 关键字。

但我想使用 Microsoft.Xna 命名空间,而不是 System

4

3 回答 3

0

您可以为您的“使用”语句创建别名以避免此问题,如下所示:

using System;
using System.Drawing;
using Forms = System.Windows.Forms;
using Microsoft.Xna.Framework.Graphics;
abstract public class GraphicsDeviceControl : Forms.Control
{
    //...
    public overide void Forms.Control.Update(...)
    protected abstract void MyNameSpace.Update(...);
}
于 2011-02-24T19:36:08.830 回答
0

我认为您不想继承自:Control,如果您想为您的 XNA 项目创建 WinForms 控件,请查看 create.msdn.com 上的示例。

如果您真的希望您的 XNA 类从 WinForms 继承,同时仍然有 XNA.Update 和 Winforms.Update 尝试更改方法名称,如下所示:

using System;
using System.Drawing;
using System.Windows.Forms;
using Microsoft.Xna.Framework.Graphics;
abstract public class GraphicsDeviceControl : Control
{
    //....
    public overide void System.Windows.Forms.Control.Update(...)
    protected abstract void MyNameSpace.Update(...);

}
于 2011-01-20T15:35:38.730 回答
0

我想他可能一直在使用这个:http ://create.msdn.com/en-US/education/catalog/sample/winforms_series_1并且想知道如何让更新周期运行。

最好的办法是使用秒表(System.Diagnostics),在 initialize 中对其进行初始化,然后使用 stopwatch1.Elapsed,就像它是你的 gameTime 变量一样。如果您将 Application.Idle 连接到 Invalidate(),则 Draw() 函数将被一遍又一遍地调用。然后,您可以从此处调用更新函数。

我知道这是旧的,但我找到了这个,所以其他人可能会找到它。一个用于互联网。

class YourDevice : GraphicsDeviceControl
{
    private Stopwatch timer;

    protected override void Initialize()
    {
        timer = Stopwatch.StartNew();
        Application.Idle += delegate { Invalidate(); };
    }

    protected override void Draw()
    {
        Update(timer.Elapsed);
    }

    private void Update(TimeSpan gameTime)
    {
        // etc
    }
}
于 2012-01-10T11:51:48.147 回答