在C#中反转数字 [英] Invert Number in C#
本文介绍了在C#中反转数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有一种简单的方法可以使用C#函数反转数字?我正在使用XNA,我想告诉我的程序,如果我的变量"超出一定数量,则必须将其值反转.关键是要产生反弹效果.
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
}
推荐答案
只需在其前面敲一个-
标志:
Just whack a -
sign in front of it:
direction.X = -direction.X;
这篇关于在C#中反转数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文