XNA:mouseState的位置重要吗
本文关键字:位置 mouseState XNA | 更新日期: 2023-09-27 18:27:00
为了从MouseState获得单击响应,我使用了这一行。
currentMouseState.LeftButton == ButtonState.Pressed && oldMouseState.LeftButton == ButtonState.Released)
在方法的最后,我有一行设置鼠标状态。
oldMouseState = currentMouseState;
我想问你的是,在一个有多个循环的方法中,上面这条线的位置重要吗?这是吗
foreach (blah blah in blahs)
{
if (something is something)
{
if (currentMouseState.LeftButton == ButtonState.Pressed && oldMouseState.LeftButton == ButtonState.Released)
{
do something
}
}
}oldMouseState = currentMouseState;
与此不同?
foreach (blah blah in blahs)
{
if (something is something)
{
if (currentMouseState.LeftButton == ButtonState.Pressed && oldMouseState.LeftButton == ButtonState.Released)
{
do something
}
}oldMouseState = currentMouseState;
}
在第一个示例中,您的mouseState更新位于FOREACH循环之外。这使得FOREACH循环中的所有内容都在mouseState更新之前执行。
在第二个例子中,您在FOREACH循环中更新了mouseState,这很奇怪,但如果您这样做了,在第一个循环项之后,第二个if语句将失败,您将不会"做某事"。