gpt4 book ai didi

c# - 如何在我的 XNA 游戏中实现类似 OnExit 的方法?

转载 作者:太空狗 更新时间:2023-10-30 00:27:59 24 4
gpt4 key购买 nike

C# XNA 游戏是否有任何方法可以检测用户是单击十字按钮关闭程序,还是按下 ALT+F4 键关闭..?

可能可以从 KeyBoardState 检测到 ALT+F4 键,但是我如何检测到单击十字按钮以关闭窗口?

我需要这个,这样我就可以在用户通过任何方式关闭游戏时关闭所有正在运行的线程。我目前有一些线程在关闭游戏时仍在运行,这使得音乐仍在播放:P

请注意,该方法必须兼容 Windows 和 Xbox 360,因为游戏应该在这两个平台上运行(可能还有 Zune)..

最佳答案

要么覆盖 OnExiting Game 的方法或订阅其 Exiting事件。

例子:

protected override void OnExiting(Object sender, EventArgs args)
{
base.OnExiting(sender, args);

// Stop the threads
}

关于c# - 如何在我的 XNA 游戏中实现类似 OnExit 的方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4385471/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com