phadaphunk
phadaphunk

Reputation: 13283

Invert Number in C#

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
                }

Upvotes: 14

Views: 30529

Answers (2)

Anon
Anon

Reputation: 101

or you can try using Vector.X * -1

Upvotes: 10

Andrew Cooper
Andrew Cooper

Reputation: 32576

Just whack a - sign in front of it:

direction.X = -direction.X;

Upvotes: 45

Related Questions