如何在 XNA 中用户按住手指时连续执行操作

发布于 2024-11-18 13:45:11 字数 100 浏览 2 评论 0原文

我有一个当用户按住手指时的操作,但是当用户按住手指时如何连续执行此操作?例如我想要:moveRight += 10;当用户将手指按住屏幕右侧时连续。有谁知道如何在 XNA 中执行此操作?

I have an action for when the user holds down their finger, but how do I continuously do this action as the user holds down his finger? For example I want to: moveRight += 10; continuously while the user holds down their finger on the right part of the screen. Does anyone know how to do this in XNA?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

水波映月 2024-11-25 13:45:11

使用鼠标输入 API (为了在 WP7 上轻松进行单点触控输入),请特别检查:

MouseState ms = Mouse.GetState();
if(ms.LeftButton == ButtonState.Pressed && ms.X > centerOfScreen)
{
    DoSomething();
}

或使用 触摸输入 API

TouchCollection touches = TouchPanel.GetState();
foreach(TouchLocation touch in touches)
{
    if((touch.State == TouchLocationState.Pressed
            || touch.State == TouchLocationState.Moved)
            && touch.Position.X > centerOfScreen)
    {
        DoSomething();
        break;
    }
}

Use either the mouse input API (for easy, single-touch input on WP7), specifically check:

MouseState ms = Mouse.GetState();
if(ms.LeftButton == ButtonState.Pressed && ms.X > centerOfScreen)
{
    DoSomething();
}

Or use the touch input API on WP7:

TouchCollection touches = TouchPanel.GetState();
foreach(TouchLocation touch in touches)
{
    if((touch.State == TouchLocationState.Pressed
            || touch.State == TouchLocationState.Moved)
            && touch.Position.X > centerOfScreen)
    {
        DoSomething();
        break;
    }
}
玩世 2024-11-25 13:45:11

当他们松开手指时有动作吗?如果是这样,则使用循环结构(游戏循环)并添加一些输入状态,而不是仅响应事件。

  • 当您收到“hold”事件时,将该状态设置为“true”
  • 当您收到表明“hold”事件结束的事件时,将其设置为“false”
  • 检查循环中的布尔值,并增加您的 x 值(或 x速度)(如果已设置)

查看 的文档Windows Phone 手势支持

也许您想要处理的“release”事件是 ManipulationCompleted 事件。不过,我无法判断它是仅限 Silverlight,还是同时支持 Silverlight 和 XNA...

如果失败,也许您可​​以处理较低级别的事件。

手势是整套运动的抽象。 API 的设计目的是完成所有肮脏的工作,即弄清楚发生了什么,并告诉您它确实发生了,而不是它是如何发生的。如果您想要比这更细粒度的控制,那么您需要更细粒度的 API。

请参阅:http://msdn.microsoft.com/ en-us/library/ff607287(v=VS.95).aspx(可能是 Touch 类 )。

Is there an action for when they release their finger? If so, then use a looping structure (game loop) and add some input state, rather than only responding to events.

  • Set that state to "true" when you get the "hold" event
  • Set it to "false" when you get the event stating that the "hold" event is over
  • Check that boolean in your loop, and increment your x value (or x velocity) if it is set

Looking at The docs for Gesture Support for Windows Phone.

Maybe your "release" event that you want to handle is the ManipulationCompleted event. I can't tell if it is Silverlight-only, or both Silverlight and XNA, though...

And if that fails, maybe there are lower level events you can handle.

Gestures are abstractions for entire sets of motion. The API is designed to do all the dirty work of figuring out what happened, and telling you that it did happen, not how it happened. If you want to have finer grain control than that, then you need a finer grained API.

See: http://msdn.microsoft.com/en-us/library/ff607287(v=VS.95).aspx (possibly the Touch class).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文