I have a while loop that runs the logic of a simple 2d game I am developing. Inside it I have a lot of function calls that seem to be varying in speed which makes the ball in the game stutter a lot. I wanted to try to make each loop last the same amount of time to eliminate the stutter.
I have tried to limit the amount of function calls which didn't work because even with the fewest amount it still did stutter. I have also tried using pause() to save time but that just made it go slower.
private void turn() {
Ball ball = new Ball(400, 500);
add(ball);
pause(3000);
while(ball.getCenterY() + ball.getRadius() <= CANVAS_HEIGHT){
ball.updatePosition(1);
wallPaddleCollision(ball);
brickCollision(ball);
if (numberOfBricks == 0) {
System.out.println("You've Won!");
}
pause(1);
}
lives--;
if(lives > 0) {
remove(ball);
turn();
}
else {
loss();
}
}
...
More code in here.
...
}
It should be running smoother than this. Any advice?