XNA保持屏幕以移动对象

劳伦斯·托尼(Laurensius Tony)

我正在使用xna与Windows Phone游戏合作...并寻找一种方法使我的对象移动并保持一些我将其作为屏幕上的按钮的矩形....

我已经尝试过了,但是它只读取了点击手势

          foreach (GestureSample gestureSample in input.Gestures)
                {
                    switch (gestureSample.GestureType)
                    {
                      case GestureType.Hold:
                      case GestureType.Tap:
                      Point tapLocation = new Point((int)gestureSample.Position.X, (int)gestureSample.Position.Y);
                      if (rightRectangle.Contains(tapLocation))
                                {
                                        rightTouched = true;
                                        player.Catapult.CurrentState = CatapultState.MoveRight;
                                        playerPositionUpdate.X += 20;
                                        player.catapultPosition.X += 20;
                                        player.Catapult.catapultPosition.X += 20;
                                        player.Catapult.projectilePositionUpdate.X += 20;
                                        if (player.Catapult.catapultPosition.X == player.Catapult.catapultPosition.X + 20)
                                            rightTouched = false;
                                        CenterOnPosition(player.Catapult.Position - catapultCenterOffset);
                                    }
                       break;
                      }
                 }
菲斯普

如上所述,您不应将其GestureSample用于此目的,因为使用dragcomplete和freedrag有点棘手。相反,您应该使用以下代码编写自己的手势TouchPanel.GetState()

TouchCollection touchCollection = TouchPanel.GetState();
        if (touchCollection.Count == 1)
        {
            var touch = touchCollection[0]; 
            switch (touch.State)
            {
                case TouchLocationState.Pressed:
                    if (rectangle.Contains((int) touch.Position.X, (int)  touch.Position.Y))
                    {
                        isMoving = true;
                    }
                    break;
                case TouchLocationState.Moved:
                    if (isMoving)
                    {
                        TouchLocation prevLocation;
                        touch.TryGetPreviousLocation(out prevLocation);
                        if (prevLocation.Position != touch.Position)
                        {
                            Vector2 delta = touch.Position - prevLocation.Position;
                            //offset your rectangle on delta
                        }
                    }
                    break;
                case TouchLocationState.Released:
                    isMoving = false;
                    break;
            }
        }
        else if (touchCollection.Count == 2)
        {
            var touchOne = touchCollection[0];
            var touchTwo = touchCollection[1];
            //pinch logic here
        }    

我想你明白这个主意。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章