# Waiting specific time to increase sound libgdx

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.

• 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. – 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 () {
if(volumeIncreasing){
elapsedTime=(System.nanoTime()-actionBeginTime)/1000000000.0f;
if(elapsedTime>0.5f){
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.

• 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. – arielsan Mar 6 '12 at 12:28