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