简体   繁体   中英

Change object animation speed in Java

I'm trying to write the classic game Breakout , which is part of an assignment from the Stanford CS106A course that I'm taking online. One problem I'm having is that the assignment gives constants to some of the game's aspect, like the speed of the ball, which is at vx = 3 and vy = 3. However, with this speed the ball in my program just moves at lightning speed, and I have to alter the constant to .003 (1000 times!) to get a playable speed, and my computer's fan starts roaring every time after running the program for like 10 seconds.

Since it's an assignment, the numbers they give can't be wrong. I guess the problem is that Eclipse runs the program too fast. So how do I use the original constants but still have a playable speed? I've been searching for answers but none of them are relatable. Thanks so much.

Also, I've just started programming for about 1 month so I'd appreciate if you can make it easier to understand!

From what I can hear it sounds like your game loop doesn't pause after each step, making it so that your game is essentially running in a short infinite loop.

So essentially, make sure you end the moveBall function with pause (DELAY); . The DELAY constant decides how fast your game runs.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM