XNA鼠标移动 [英] XNA Mouse Movement

查看:180
本文介绍了XNA鼠标移动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做了XNA中的几场比赛之前,我要开始一个新项目。有一件事我想要做的是有鼠标的移动。

I've made a few games in XNA before and I'm about to start a new project. One thing I'd like to do is have the mouse movement.

只是为了澄清(因为我已经看到了一些类似的问题导致混淆),我想要得到的鼠标的移动。光标的不是位置或位置从一帧到下一帧的变化。我只想如何鼠标已被移动的数据。

Just to clarify (as I've seen some similar questions lead to confusion) I want to get the movement of the mouse. Not the position of the cursor or the change in position from one frame to the next. I would simply like data about how the mouse has been moved.

在我以前的比赛我只是(隐藏)光标复位到视口的中间,看着位置的变化。然而,这似乎是在骗一点,导致我的代码有些凌乱寻找计算。

In my previous game I simply reset the (hidden) cursor to the middle of the viewport and looked at the change in position. However this seems at little bit of a cheat and leads to some messy looking calculations in my code.

那么,有没有办法让鼠标移动返回到程序?

So is there any way to have the mouse movement returned to the program?

谢谢,
马特

编辑:

在响应第一条评论。光标,我指的是在这种情况下的位置是鼠标指针的位置在屏幕上。鼠标我指的是所述的运动pysically移动鼠标。

In response to first comment. The position of the cursor I'm refering to in this case is the position onscreen of the mouse pointer. The movement of the mouse I'm refering to is pysically moving the mouse.

XNA似乎有字的鼠标与指针(或光标)的代名词。

XNA seems to have the word mouse to be synonymous with pointer (or cursor).

的问题,我'米有是,尽管鼠标向左移动,我不能在程序运行为光标在屏幕的边缘。

The problems I'm having is that despite the mouse moving left, I can't get that movement in the program as the cursor is at the edge of the screen.

推荐答案

MouseState 的类包括仅鼠标光标的位置,等等。这一立场将,正如你提到的,夹在屏幕的边缘。没有办法来确定用户是否移动比通过MouseState类其他鼠标。特别是,没有MouseDirection,MouseTangent,或指示鼠标移到哪个方向MouseAngle属性。

The MouseState class includes only the position of the mouse cursor, among other things. This position will, as you mentioned, clip to the edges of the screen. There is no way to determine whether the user moved the mouse other than through the MouseState class. In particular, there is no MouseDirection, MouseTangent, or MouseAngle property that indicates which direction the mouse was moved.

作为一种解决方法,你可以调用的 SETPOSITION 强制光标在屏幕的中间,这样你就可以随时知道哪个方向的鼠标已经移动。事实上,即使SETPOSITION建议使用此方法:

As a workaround, you can call SetPosition to force the cursor at the middle of the screen, so you can always know which direction the mouse has moved. In fact, SetPosition even recommends this approach:

在使用此方法采取相对投入,比如在
一线人游戏中,鼠标的位置设置为您
游戏窗口中每个帧的中央。这将允许您阅读
与粒度量最大的两个轴的鼠标移动。

When using this method to take relative input, such as in a first-person game, set the position of the mouse to the center of your game window each frame. This will allow you to read mouse movement on both axes with the greatest amount of granularity.

这篇关于XNA鼠标移动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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