开发者

Windows forms and XNA - Draw is not realtime

开发者 https://www.devze.com 2023-01-24 08:31 出处:网络
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

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?


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.

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

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

0

精彩评论

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