if (Touch.State == TouchLocationState.Pressed)
{
curTouchPoint = new Point((int)Touch.Position.X, (int)Touch.Position.Y);
FlickActive = true;
}
if (Touch.State == TouchLocationState.Moved)
{
prevTouchPoint = curTouchPoint;
curTouchPoint = new Point((int)Touch.Position.X, (int)Touch.Position.Y);
if (FlickActive)
{
for (int i = 0; i < Balls.Length; i++)
{
if(Balls[i].Rect.Contains(curTouchPoint))
{
Balls[i].Direction = new Vector2(curTouchPoint.X - prevTouchPoint.X,
curTouchPoint.Y - prevTouchPoint.Y);
Balls[i].Direction.Normalize();
FlickActive = false;
Score += 100;
return;
}
}
}
}
So as you can see, basically what I do, is subtract the current point from the last point. However, what's happening is that sometimes, for some reason, the ball will go to the top left corner, what's supposedly (0,0). I had no idea why this happened, so I did some simple debugging, and found that the value of my direction Vector was NaN, along with my Position Vector. I'm not sure why this happens, I've done some research online and it says it's the Normalize() part of it, but I haven't been able to find why exactly this happens. I've heard it's something like the square root of something, however, it only happens certain times, when I'm flicking, I've been unable to debug a way to find out how exactly it occurs. Any explanation as to why this happens or a method to solve would be greatly appreciated.
Thanks!

New Topic/Question
Reply



MultiQuote



|