获取触摸位置并点击monogame

时间:2016-06-04 19:08:38

标签: android monogame

我正在为我的学校项目用Android的monogame编写一个游戏,但我无法通过触摸位置做一个简单的点击操作,我搜索但是找不到任何有用的东西。我的游戏是一个管道益智游戏,当玩家触摸它旋转的管道时,我想要,但正如我所说,我不能这样做。这是我的键盘输入代码。

        KeyboardState newState = Keyboard.GetState();
        if (oldState.IsKeyUp(Keys.Space) && newState.IsKeyDown(Keys.Space))
        {
                angle1 += (float)Math.PI / 2.0f;
        }
        oldState = newState;

1 个答案:

答案 0 :(得分:3)

您想要添加以下内容的检查:

TouchCollection touchCollection = TouchPanel.GetState();

    if (touchCollection.Count > 0)
    {
         //Only Fire Select Once it's been released
         if (touchCollection[0].State == TouchLocationState.Moved || touchCollection[0].State == TouchLocationState.Pressed)
         {
              Console.WriteLine(touchCollection[0].Position);
         {
    }

然后,您可以使用“位置”变量执行任何操作。

相关问题