的XNA Game不更新而"拖"窗口,任何事件处理程序? [英] XNA Game does not update while "dragging" window, any event handlers?

查看:204
本文介绍了的XNA Game不更新而"拖"窗口,任何事件处理程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新使用XNA和C#和我来我的XNA项目的地步,我需要比赛的时候失去焦点,这样我可以同步音乐和视觉效果,一旦它再次获得关注事件处理程序来预测。但我有一个问题;游戏不更新,而被拖累,但我似乎无法找到一个这样的合适的事件监听器。我试过:

  System.Windows.Forms.Control.FromHandle(Window.Handle).Move + =新的EventHandler( DeactivateGame); 



在移动窗口此人叫DeactivateGame万吨倍。但即使它的工作原理,尽管它调用函数不止一次的事实,我不能看到一个事件处理程序的窗口句柄被释放,使游戏中可以通过调用ActivateGame

一个阿里纳斯(如果它帮助);

  this.Activated + =新事件处理< EventArgs的>(NotifyActivated); 
this.Deactivated + =新的EventHandler< EventArgs的>(NotifyDeactivated);



这些事件处理程序最小化窗口或把注意力放在游戏窗口别的东西时,工作正常,但它没有被注册拖动窗口。所用编程一个也许很明显,但我只是想确保我已经给了足够的信息。



编辑:
我想补充的功能事件处理的结果是一个DateTime /时间跨度当窗口失焦或拖着被调用。当下降或获取再次聚焦,这会比较当前时间和设定的时间时,窗口失去焦点,计算两者之间失去的时间。


解决方案

有关被拖了XNA窗口时检测,你使用Window.Handle Windows窗体在正确的轨道上。你可以简单地听ResizeBegin和ResizeEnd事件当用户开始移动窗口时,他们释放就知道了。

  VAR xnaWinForm =(System.Windows.Forms.Control.FromHandle(Window.Handle)为System.Windows.Forms.Form中); 
如果(xnaWinForm!= NULL)
{
xnaWinForm.ResizeBegin + =新的EventHandler(xnaWinForm_ResizeBegin);
xnaWinForm.ResizeEnd + =新的EventHandler(xnaWinForm_ResizeEnd);
}

和这里的事件处理程序是什么样子。

 无效xnaWinForm_ResizeBegin(对象发件人,EventArgs五)
{
// XNA窗口开始移动。
}

无效xnaWinForm_ResizeEnd(对象发件人,EventArgs五)
{
// XNA窗口被释放,不再被移动。
}



然后,只需与您确定当窗口中提到的其他活动结合本最小化/恢复/主动来确定窗口是如何长久以来一直是不活动。


I'm new with XNA and C#, and I've come to the point in my XNA project where I need event handlers to predict when the game loses focus so that I can sync music and visuals once it gains focus again. But I got one problem; the game does not "update" while being dragged, but I can't seem to find an suitable event listener for this. I've tried:

System.Windows.Forms.Control.FromHandle(Window.Handle).Move += new EventHandler(DeactivateGame);

This one calls "DeactivateGame" tons of times while moving the window. But even if it works, despite the fact it calls the function more than once, I can't see a event handler that calls a function when the window handle is released so that the game can resume again by calling "ActivateGame"

A sidenote (if it helps);

this.Activated += new EventHandler<EventArgs>(NotifyActivated);
this.Deactivated += new EventHandler<EventArgs>(NotifyDeactivated); 

These event handlers works fine when minimizing the window or putting focus on something else than the game window, but it does not register the window being dragged. Maybe obvious for the one used to programming, but I just want to make sure I've given enough information

EDIT: The function I want to add as the result of the event handler is a DateTime/TimeSpan that gets called when the window is out of focus or dragged. When dropped or gets focus again, this will compare the current time with the time set when the window lost focus to calculate the lost time in between.

解决方案

For detecting when the XNA window is being dragged, you were on the right track using the Window.Handle with Windows Forms. You can simply listen to the ResizeBegin and ResizeEnd events to know when the user starts moving the window and when they release it.

var xnaWinForm = (System.Windows.Forms.Control.FromHandle(Window.Handle) as System.Windows.Forms.Form);
if (xnaWinForm != null)
{
    xnaWinForm.ResizeBegin += new EventHandler(xnaWinForm_ResizeBegin);
    xnaWinForm.ResizeEnd += new EventHandler(xnaWinForm_ResizeEnd);
}

And here's what the event handlers look like.

void xnaWinForm_ResizeBegin(object sender, EventArgs e)
{
    // XNA window is starting to be moved.
}

void xnaWinForm_ResizeEnd(object sender, EventArgs e)
{
    // XNA window was released and is no longer being moved.
}

Then just combine this with the other events you mentioned for determining when the window is minimized/restored/active to determine how long the window has been "inactive" for.

这篇关于的XNA Game不更新而&QUOT;拖&QUOT;窗口,任何事件处理程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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