我有一个弹跳球,我试着让它弹跳一次,速度会变快。
在我的球课上,我有一个float speed;
我初始化了它:
public ball(float speed)
speed = 1f;
我有一个球运动的方法,看起来像这样:
public void BallMovement()
{
if (movingUp) { ballRect.Y -= speed; }//Error
if (!movingUp) { ballRect.Y += speed; }//Error
if (movingLeft) { ballRect.X -= speed; }//Error
if (!movingLeft) { ballRect.X += speed; }//Error
if (ballPosition.Y < 85)
{
movingUp = false;
}
if (ballPosition.Y >= 480)
{
movingUp = true;
}
然后我在更新方法中添加这个:BallMovement();
在我尝试使用速度变量之前它工作,由于这个错误它不会编译:
无法将类型“float”隐式转换为“int”。存在显式转换(您是否缺少强制转换?)