Windows窗体和XNA - Draw不是实时的 [英] Windows forms and XNA - Draw is not realtime

查看:148
本文介绍了Windows窗体和XNA - Draw不是实时的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用通过组合Windows窗体和XNA构建的XNA级别编辑器。
我正在使用App Hub上的示例中的内容链接文本,但是我做了一些修改,所以我有一些ViewportController类管理所有的视口控件,而不是直接管理它们。
问题是当我需要更新Draw方法时,我必须摇动窗口。
任何人都知道如何解决这个问题,所以Draw会实时更新?

I am currently working on a Level Editor for XNA which is built by combining Windows Forms and XNA. I am using stuff from the example on App Hub link text, but I have made some changes, so I have some ViewportController class which manages all the viewport controls, instead of the form manages them directly. The problem is that when I need to update the Draw method I have to shake the window. Anybody knows how to fix this, so the Draw will update realtime?

推荐答案

不知道ViewportController可能是什么。但是,Draw()方法由Windows绘画请求触发。它运行Control.OnPaint()方法,在GraphicsDeviceControl类中有一个覆盖,它会导致Draw()运行。

Not sure what a ViewportController might be. However, the Draw() method is triggered by a Windows paint request. That runs the Control.OnPaint() method, there is an override for it in the GraphicsDeviceControl class which causes Draw() to run.

示例SpinningTriangleControl显示了 d得到控制重复重绘,您需要将其动画化:

The sample SpinningTriangleControl shows how you'd get a control to redraw itself repeatedly, what you'd need to get it animated:

        // Hook the idle event to constantly redraw our animation.
        Application.Idle += delegate { Invalidate(); };

注意Control.Invalidate()方法调用,这是最终导致OnPaint()方法运行的。使用空闲事件确保这一次又一次地完成,但只有当主线程没有其他任何东西忙时,对于只显示静态内容的控件,SpriteFontControl就不是必需的。另一种方法是使用一个具有短间隔的Timer,其Tick事件处理程序可以调用Invalidate()。

Note the Control.Invalidate() method call, that's what eventually causes the OnPaint() method to run. Using the Idle event ensures this is done over and over again but only if the main thread isn't otherwise busy with anything. This isn't necessary for controls that show only static content, like the sample SpriteFontControl. Another way to do it is to use a Timer with a short Interval, its Tick event handler can call Invalidate().

这篇关于Windows窗体和XNA - Draw不是实时的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆