Xna - 获取窗口位置?
我正在尝试安装 XNA WinForms 系统,这样我就可以拥有一个游戏编辑器,并且我需要使用鼠标。由于 XNA 鼠标输入类根据窗口位置报告鼠标位置,因此我需要将表单放置在同一位置。我如何获取 XNA 游戏使用的窗口的位置?
I'm trying to rig an XNA WinForms system so I can have a game editor, and I need to use the mouse for it. Since the XNA Mouse input class reports mouse position based off of the window's location, I need to place the form I have in the same spot. How can i get the location of the window that my XNA game uses?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我最终用这段代码做到了:
效果很好!
I ended up doing it with this code:
which works just dandy!
Game.Window.ClientBounds 结构的 X 和 Y 属性应该为您提供所需的绝对窗口坐标。
The
X
andY
properties of theGame.Window.ClientBounds
struct should give you the absolute window coordinates you're looking for.我的关卡编辑器也遇到了这个问题。我的 Windows 窗体中有一个图片框,因此初始化 XNA 游戏时我唯一需要做的就是:
其中
Viewport
是图片框,现在 XNA 鼠标位置会自动正确调整。
I encountered this problem too with my level editor. I have a picturebox in my windows Forms, so the only thing i needed to to when initializing the XNA game:
where
Viewport
is the pictureboxnow the XNA mouse position is adjusted properly automatically.