如何使用触摸点让我的矩形在 Windows Phone 7 中移动?

发布于 2024-10-09 15:18:49 字数 724 浏览 0 评论 0原文

我遇到了一个问题,如何在 Windows Phone 7 中使用触摸输入向上或向下移动我的简单矩形。我设法向上移动矩形并进行点击测试,但我如何知道我的触摸输入是否正在下降?

我做了一个 hitBox,这是我的代码。

        Rectangle hitbox = 
                  new Rectangle(32, 
                                GraphicsDevice.Viewport.Bounds.Height / 2 - 64,
                                32,
                                128);

        foreach (TouchLocation location in TouchPanel.GetState())
        {
            hitbox = new Rectangle((int)blueBar.X, (int)blueBar.Y, 32, 128);
            if (hitbox.Contains((int)location.Position.X, (int)location.Position.Y))
            {
                Debug.WriteLine("We’re hit!");
                blueBar.Y -= 10;
            }
        }

I'm having a problem how do I move my simple Rectangle upward or downward using Touch input in Windows Phone 7. I manage to move the rectangle upward and do a hit test but how do I know if my touch input is going down?

I made a hitBox, here's my code.

        Rectangle hitbox = 
                  new Rectangle(32, 
                                GraphicsDevice.Viewport.Bounds.Height / 2 - 64,
                                32,
                                128);

        foreach (TouchLocation location in TouchPanel.GetState())
        {
            hitbox = new Rectangle((int)blueBar.X, (int)blueBar.Y, 32, 128);
            if (hitbox.Contains((int)location.Position.X, (int)location.Position.Y))
            {
                Debug.WriteLine("We’re hit!");
                blueBar.Y -= 10;
            }
        }

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

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

发布评论

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

评论(1

一页 2024-10-16 15:18:49

与其使用矩形来点击测试用户的触摸,为什么不尝试这种方法:
http://codecube.net/2010/03/approximating-touch-points/

这个想法是,您只需激活距离触摸点“最近”的 UI 元素...这样您就不必担心混乱的碰撞检测:-)

除此之外,这是我写的一篇关于使用触摸的文章在屏幕上平滑移动精灵的点:
http://codecube.net/2010/04/smooth-control-with-触摸/

Instead of using a rectangle to hit test a user's touch, why not try this approach:
http://codecube.net/2010/03/approximating-touch-points/

The idea is that you just activate the "closest" UI element to the touch point ... that way you don't have to worry about messy collision detection :-)

Aside from that, here's an article I wrote about using touch points to smoothly move a sprite on the screen:
http://codecube.net/2010/04/smooth-control-with-touch/

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