So the rectangle on my game moves at a speed of one, but I cant change it to 0.5 of 1/2, anyone have any idea how I can slow it down?
所以我游戏中的矩形以1的速度移动,但是我不能将它改为0.5的1/2,任何人都知道如何减速它?
if(bounce1){ball.x += 1, ball.y += 1;}
if(bounce2){ball.x -= 1, ball.y -= 1;}
if(bounce3){ball.y += 1, ball.x -= 1;}
2 个解决方案
#1
1
You should elaborate on your project structure and question. I'm guessing your problem is arising because your variables 'ball.x" and "ball.y" are integer type which can not take on values that are half-integers (i.e. 0.5 or 1/2). You should go back and change those variables to doubles. That should fix your problem from my hunch. Again, you should elaborate on your code to make it easier to diagnose your problem.
您应该详细说明您的项目结构和问题。我猜你的问题正在出现,因为你的变量'ball.x“和”ball.y“是整数类型,它不能采用半整数的值(即0.5或1/2)。你应该回去将这些变量更改为双倍。这应该可以解决您的问题。再次,您应该详细说明您的代码,以便更容易诊断您的问题。
#2
0
A way to change the speed of the ball without interfering with the 1 value would be changing the refresh rate of the game. If you use a timer object to update the position you could simply change the int value.
在不干扰1值的情况下改变球速的方法将改变游戏的刷新率。如果使用计时器对象更新位置,则只需更改int值即可。
Timer tm = new Timer(this, 8);
The object above creates a timer that refreshes every 8 ms. Changing the int will increase or speed up the refresh rate.
上面的对象创建一个每8毫秒刷新一次的计时器。更改int将增加或加快刷新率。
#1
1
You should elaborate on your project structure and question. I'm guessing your problem is arising because your variables 'ball.x" and "ball.y" are integer type which can not take on values that are half-integers (i.e. 0.5 or 1/2). You should go back and change those variables to doubles. That should fix your problem from my hunch. Again, you should elaborate on your code to make it easier to diagnose your problem.
您应该详细说明您的项目结构和问题。我猜你的问题正在出现,因为你的变量'ball.x“和”ball.y“是整数类型,它不能采用半整数的值(即0.5或1/2)。你应该回去将这些变量更改为双倍。这应该可以解决您的问题。再次,您应该详细说明您的代码,以便更容易诊断您的问题。
#2
0
A way to change the speed of the ball without interfering with the 1 value would be changing the refresh rate of the game. If you use a timer object to update the position you could simply change the int value.
在不干扰1值的情况下改变球速的方法将改变游戏的刷新率。如果使用计时器对象更新位置,则只需更改int值即可。
Timer tm = new Timer(this, 8);
The object above creates a timer that refreshes every 8 ms. Changing the int will increase or speed up the refresh rate.
上面的对象创建一个每8毫秒刷新一次的计时器。更改int将增加或加快刷新率。