如何使用触摸点让我的矩形在 Windows Phone 7 中移动?
我遇到了一个问题,如何在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
与其使用矩形来点击测试用户的触摸,为什么不尝试这种方法:
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/