0

我正在处理点击事件,我不介意更新和绘制的闪电般的速度处理,这就是为什么我只是使用一个简单的按钮按下事件来处理点击。但是和其他程序员一样,我在使用这种方法时遇到了一个问题,我正在添加像 score += 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;
    }
}

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

4

1 回答 1

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;
    }
}
于 2013-03-07T14:23:23.490 回答