• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how can I get my game to pause in between rounds?

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hopefully this is another easy question. I'm still building my bat_and_ball game (see my post from yesterday) and I'm stuck again.

When my player fails to hit the ball back the ball goes out of play. The game plays a short piece of "you lost" music before restarting with a new ball. I want the game to pause for a few seconds while the music plays to give the player time to breathe, but at the moment it just plays the music and immediately restarts the game. Is there a simple way to tell my game to wait 5 seconds?

Here's the method:


and...

as you can see, I tried to use a For loop to count down the time (as I used to do in BASIC) but this doesn't work... (why doesn't it work? is it something to do with threads?)

I also tried this:


but when the ball went out it threw the error: "current thread not owner"

Can anyone help me please?
 
Sheriff
Posts: 4313
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
the problem with something like this

is that your computer could be REALLY fast and that loop will happen real quick. -- so you're not really timing anything.

what if instead of doing wait(1000) you call sleep(1000)? does that fix the Exception?

Also -- what if instead of automatically restarting after X seconds you instead pop up a button that says [restart?] that way the person can wait as long or as short as they want before they try again. And that way you can avoid the whole wait issue....

And lastly, I'm moving this to my snazzy games forum -- cause this is a game, and we need some more traffic!
[ August 24, 2004: Message edited by: Jessica Sant ]
 
blacksmith
Posts: 1332
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try calling sleep() statically: "Thread.sleep(1000)" instead of "wait(1000)".

If that doesn't work, maybe tell us what kind of exception was thrown, and maybe give us a stack trace?
 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is a simple timer class, just make a new one passing the time in seconds and then call t.time() and it will block till thr time has expired.


[ August 24, 2004: Message edited by: J Kneeland ]
 
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic