• Log in or sign up for an account here: https://www.sythe.org/login

Hopefully a simple problem....

slashshot007

Active Member
Joined
May 6, 2006
Sythe Gold
0
Messages
164
for making games, in java, how would i make it so i can, for example, make a ball bounce, without using a timer?
I made a super cool breakout game(not really that great) but the problem is, it isn't the fastest, becuase the ball moves through a timer.

so how do i do this without a timer? (i dont use an applet, i have everything in a "BreakoutPanel" which extends JPanel)

(I'll release the source to the breakout game when it is completely finished)

thanks in advance.
 
Member of the Month Winner
Sythe's 10th Anniversary
for making games, in java, how would i make it so i can, for example, make a ball bounce, without using a timer?
I made a super cool breakout game(not really that great) but the problem is, it isn't the fastest, becuase the ball moves through a timer.

so how do i do this without a timer? (i dont use an applet, i have everything in a "BreakoutPanel" which extends JPanel)

(I'll release the source to the breakout game when it is completely finished)

thanks in advance.
Does it not make sense to use a timer? What you need to get correct is the speed of the ball, as well as other forces involved. A timer simply serves as a refresher.

Of course, you could fashion your own timer as well, I believe. All you need to do is create a new thread which measures milliseconds. I'm not sure how you would do it in Java, but in .Net I would call the Windows GetTickCount() API twice (returns a millisecond value of how long the computer has been running) and find out the difference between them. I'm unsure how else to do it, but whenever I've done anything similar to this, I've used timers or threads.
 
Code:
long currentTime = System.currentTimeMillis();
To make it into a timer you would just take the current time prior to starting the operation(s) and then take the current time again after, substract them, and continue if a certain amount of time has elapsed and loop again if it hasn't.
 
ok, well i wasn't planning on actually makinga timer, but to use it without.
but anyways the solutions was threads, i looked it up, and it works great now.
I just wasn't familiar with threads at all, but they are VERY convenient, and I will use them LOTS in the future.
 
Runescape Gamblingrunescape gambling
Back
Top