Cannot Implicitly Convert Type in XNA

前端 未结 4 1945
夕颜
夕颜 2021-01-24 20:19

i have a bouncing ball, and i tried to make so when it bounces once, the speed gets higher.

In my ball class, i have a float speed;

and i initialize

4条回答
  •  一个人的身影
    2021-01-24 20:57

    You're trying to subtract a float value (ex: 1.223488) from an int (ex: 12); You can't do this. Either convert (cast) both values to floats, or convert (cast) both values to ints:

     if (movingUp) { ballRect.Y -= (int)speed; }//Error
    

    The error is basically saying "We can't automatically convert this for you (implicit), but you can convert it yourself (explicit)." I'd check out the MSDN article on type casting: http://msdn.microsoft.com/en-us/library/ms173105.aspx

提交回复
热议问题