0

我目前正在 VS2012 上使用 C#/XNA 构建游戏,在我的代码中,我希望用户在切换到垂直或水平手势时触摸一个对象并垂直和水平拖动它,而不用抬起手指。这是我的代码示例:

protected override void Update(GameTime gameTime)
    {
        // Allows the game to exit
        if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            this.Exit();

        // Move the sprite by speed, scaled by elapsed time. 
        //shipPosition += shipSpeed; 

        // check whether gestures are available
        while (TouchPanel.IsGestureAvailable)
        {
            // read the next gesture
            GestureSample gesture = TouchPanel.ReadGesture();

            // has the user tapped the screen?
            switch (gesture.GestureType)
            {
                case GestureType.HorizontalDrag:

                    shipPosition += gesture.Delta;

                    break;
                case GestureType.VerticalDrag:

                    shipPosition += gesture.Delta;

                    break;
            }
        }

        // Make sure that the ship does not go out of bounds 
        shipPosition.X = MathHelper.Clamp(shipPosition.X, 35 / 2 , 765 + 35 / 2 - shipTexture.Width);
        shipPosition.Y = MathHelper.Clamp(shipPosition.Y, 21 / 2, 451 + 21 / 2 - shipTexture.Height);

        // TODO: Add your update logic here

        base.Update(gameTime);
    }

有人可以建议吗?我在某处看到我必须使用原始输入触摸,但我想知道它是如何与拖动一起工作的。

4

1 回答 1

0

听起来您需要改用 Touch Location

http://msdn.microsoft.com/en-us/library/ff434208.aspx

往下看

从触控输入设备获取多点触控数据

于 2013-02-01T17:22:04.107 回答