Reputation: 10865
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;
}
}
Upvotes: 0
Views: 2602
Reputation: 47749
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/
Upvotes: 1