Xna 和 System 命名空间冲突

发布于 2024-10-12 11:06:05 字数 503 浏览 5 评论 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

i'm trying to declarate new abstract class

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

    protected abstract void Update();

}

but when i compiled it i had got this warning:

'WinFormsContentLoading.GraphicsDeviceControl.Update()'
hides inherited member
'System.Windows.Forms.Control.Update()'.
Use the new keyword if hiding was
intended.

but i would like to use Microsoft.Xna namespace, not System

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

も星光 2024-10-19 11:06:05

我认为您不想继承: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(...);

}

I don't think you want to inherit from : Control, if you want to create a WinForms control of your XNA project then please see the samples on create.msdn.com.

If you really want your XNA class to inherit from WinForms, while still have both the XNA.Update and the Winforms.Update try changing the method names like this:

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(...);

}
反差帅 2024-10-19 11:06:05

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

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(...);
}

You may be able to create aliases for your 'using' statements to avoid this issue like so:

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(...);
}
放飞的风筝 2024-10-19 11:06:05

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

最好的办法是使用秒表(System.Diagnostics),在初始化中初始化它,然后使用 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
    }
}

I think he may have been using this: http://create.msdn.com/en-US/education/catalog/sample/winforms_series_1 and wondering how to get an update cycle to run.

Best thing to do is use a Stopwatch (System.Diagnostics), initialise it in initialize and then use stopwatch1.Elapsed like it is your gameTime variable. The if you hook up Application.Idle to Invalidate() then the Draw() function will be called over and over. You can then call an update function from here.

I know this is old but I found this, so someone else may find it. One for the internets.

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
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文