Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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.

share|improve this question
1  
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

1 Answer 1

up vote 3 down vote accepted

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.

share|improve this answer
2  
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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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