处理xna游戏工作室中的快速点击

时间:2013-03-07 14:10:17

标签: c# xna click

我正在处理点击事件,我不介意更新的闪电速度处理和绘制,这就是为什么我只是使用一个简单的按钮按下事件来处理点击。但是和任何其他程序员一样,我在使用这种方法时遇到了问题,我正在添加得分+ = 100等分数,正如您所猜测的那样,分数的增加非常快,我认为只需点击一下得分增加了200-400。这是我如何做到的。

mouseStateCurrent = Mouse.GetState();
                mousePosition = new Point(mouseStateCurrent.X, mouseStateCurrent.Y);
                if (drawPauseMenu == false)
                {
                    if (pauseBtnRec.Contains(mousePosition))
                    {
                        if (mouseStateCurrent.LeftButton == ButtonState.Pressed)
                        {
                            drawPauseMenu = true;
                            paused = true;
                        }
                    }
                    else if (binRec.Contains(mousePosition))
                    {
                        if (mouseStateCurrent.LeftButton == ButtonState.Pressed)
                        {
                            playerScore += 100;
                            binSelected = 1;
                        }

                    }
                    else if (birdBathRec.Contains(mousePosition))
                    {
                        if (mouseStateCurrent.LeftButton == ButtonState.Pressed)
                        {
                            playerScore += 100;
                            birdBathSelected = 1;
                        }

                    }
                    else if (bowlRec.Contains(mousePosition))
                    {
                        if (mouseStateCurrent.LeftButton == ButtonState.Pressed)
                        {
                            playerScore += 100;
                            bowlSelected = 1;
                        }

                    }
                    else if (cansRec.Contains(mousePosition))
                    {
                        if (mouseStateCurrent.LeftButton == ButtonState.Pressed)
                        {
                            playerScore += 100;
                            cansSelected = 1;
                        }

                    }
                    else if (paintsRec.Contains(mousePosition))
                    {
                        if (mouseStateCurrent.LeftButton == ButtonState.Pressed)
                        {
                            playerScore += 100;
                            paintsSelected = 1;
                        }

                    }
                    else if (poolRec.Contains(mousePosition))
                    {
                        if (mouseStateCurrent.LeftButton == ButtonState.Pressed)
                        {
                            playerScore += 100;
                            poolSelected = 1;
                        }

                    }
                    else if (pothRec.Contains(mousePosition))
                    {
                        if (mouseStateCurrent.LeftButton == ButtonState.Pressed)
                        {
                            playerScore += 100;
                            potSelected = 1;
                        }

                    }
                    else if (tiresRec.Contains(mousePosition))
                    {
                        if (mouseStateCurrent.LeftButton == ButtonState.Pressed)
                        {
                            playerScore += 100;
                            tiresSelected = 1;

                        }

                    }
                    else if (vasesRec.Contains(mousePosition))
                    {
                        if (mouseStateCurrent.LeftButton == ButtonState.Pressed)
                        {
                            playerScore += 100;
                            vasesSelected = 1;
                        }

                    }
                    mouseStatePrevious = mouseStateCurrent;
                }

尝试使用此代码并尝试这样做,

if (mouseStateCurrent.LeftButton == ButtonState.Pressed)
{

    if (mouseStateCurrent.LeftButton == ButtonState.Released)
    {
        playerScore += 100;
        vasesSelected = 1;
    }
}

这仍然没有运气。有任何想法吗?谢谢!

1 个答案:

答案 0 :(得分:1)

你快到了。你有一个mouseStatePrevious并且你正确设置它,但你从来没有使用它。

而不是:

if (mouseStateCurrent.LeftButton == ButtonState.Pressed)
{ // Why are you checking if the mouse is pressed AND released?
    if (mouseStateCurrent.LeftButton == ButtonState.Released)
    {
        playerScore += 100;
        vasesSelected = 1;
    }
}

这样做:

if (mouseStateCurrent.LeftButton == ButtonState.Pressed)
{
    if (mouseStatePrevious.LeftButton == ButtonState.Released)
    {
        playerScore += 100;
        vasesSelected = 1;
    }
}
相关问题