问题
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