I want to wait a moment (.5 seconds) before I increase the sound, how can i achieve this without using Thread.sleep, because i want my game to keep runnig.

  • 1
    \$\begingroup\$ When you say "increase sound" do you mean increasing the volume? This seems like a game logic problem: you just have some counter somewhere that ticks off the time then does what you want it to do. \$\endgroup\$ – Tetrad Mar 5 '12 at 7:20

You can either use a java timer approach: http://developer.android.com/reference/java/util/Timer.html

Or you could simply keep track of the time elapsed since the increase volume action began. Maybe something like this in your render method or somewhere else:

float elapsedTime;
long actionBeginTime;
boolean volumeIncreasing=false;
public void render () {
            increaseVolume(); //your method that increases volume
            volumeIncreasing=false; //can be set here or in increaseVolume()

Of course you need to set volumeIncreasing to true and actionBeginTime=System.nanoTime() somewhere when the action begins.

| improve this answer | |
  • 3
    \$\begingroup\$ Only to add that LibGDX has its own delta value implementation (it uses System.nanoTime() internally) and you get it by calling Gdx.graphics.getDeltaTime(). That way you don't have to calculate by hand the elapsedTime. \$\endgroup\$ – arielsan Mar 6 '12 at 12:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.