处理快速点击在xna游戏工作室
本文关键字:xna 游戏 工作室 处理 | 更新日期: 2023-09-27 18:02:50
我正在处理点击事件,我不介意更新和绘制的闪电速度处理,这就是为什么我只是使用一个简单的按钮按下事件来处理点击。但就像其他程序员一样,我在使用这种方法时遇到了一个问题,我添加的分数是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;
}
}
仍然没有运气。什么好主意吗?谢谢!
你就快成功了。你有一个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;
}
}