Xna 新华社:穆萨的地位重要吗?

Xna 新华社:穆萨的地位重要吗?,xna,c#,Xna,C#,为了从MouseState获得一个单击响应,我使用了这一行 currentMouseState.LeftButton == ButtonState.Pressed && oldMouseState.LeftButton == ButtonState.Released) 在方法的末尾,我有一行设置鼠标状态 oldMouseState = currentMouseState; 我想问你的问题是,在一个有多个循环的方法中,上述行的位置是否重要?这是: for

为了从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语句将失败,您将不会“做些什么”。

您肯定可以通过运行代码来调查问题的结果。对我来说似乎很明显