Invert Number in C#

拈花ヽ惹草 提交于 2020-12-08 05:45:37

问题


Is there an easy way to invert a number in C# with a function? I'm using XNA and i'd like to tell my program that if my 'variable' gets beyond a certain number it has to invert it's value. The whole point is to give a rebound effect.

     if (ballPosition.X >= screenWidth)
                {
                    // Invert the ball Direction Vector.X
                }

回答1:


Just whack a - sign in front of it:

direction.X = -direction.X;



回答2:


or you can try using Vector.X * -1



来源:https://stackoverflow.com/questions/9765317/invert-number-in-c-sharp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!