我正在使用C#和XNA为Windows Phone 8制作游戏。游戏涉及在屏幕上拖动对象。 update方法使用以下代码移动对象。
//Check for input on the touchscreen
GestureSample gesture = TouchPanel.ReadGesture();
//'selectedObject' is a variable of type 'GameObject' - It refers to the current object that is being moved
if (selectedObject == null)
{
//The method checks which game object to use as the selected object if one is not already being moved
foreach (GameObject gameObject in gameObjects)
{
//Check if the input is a dragging motion and that the user's input intersects with the objects hitbox
if (gesture.GestureType == GestureType.FreeDrag && gameObject.Hitbox.Contains((int)gesture.Position.X, (int)gesture.Position.Y))
{
//Make 'selectedObject' refer to the newly touched game object
selectedObject = gameObject;
//'selectedPosition' is a 'Vector2' that is used in the drawing method to draw the selected object at a specific point on the screen
selectedPosition = gesture.Position;
break;
}
}
}
else
{
//If an object is currently being moved, update its position
selectedPosition = gesture.Position;
}
代码成功移动了正确的对象并显示它们被移动。但是,物体的运动明显延迟。如果用户的手指在拖动对象时在屏幕上向上移动,则该对象需要几秒钟才能赶上。所选对象的移动不会减慢其他对象的速度(它们随机移动并继续以与用户开始交互之前相同的速度移动)。如何防止此延迟并显示实时移动所选对象(即,当用户的手指向一个方向移动时,对象会立即显示,而不是停留一秒然后重复操作)?