开发者

Xna and System namespace conflict

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


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

}


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


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
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜