lundi 4 avril 2016

How To Check If Void Method is Called in If Statement

So I'm developing a game in Java using Box2D Engine.

For one part, when a collision is made with a trampoline/pogo stick - I want to play sound. I can do this but I don't want it to play the sound every time I collide with it as its very laggy. So I only want it to play the sound when it is colliding with the object and the robot.jump(15) is performed. So is there a way I can check if this void jump method is called in an if statement?

Here is my current code which plays sound every time a collision is made.

else if (e.getReportingBody() instanceof Trampoline) {
            robot.jump(15);

            try {
                gameMusic = new SoundClip("data/trampolinemusic.wav");   // Open an audio input stream
                gameMusic.play();  // Set it to continous playback (looping)
            } catch (UnsupportedAudioFileException|IOException|LineUnavailableException a) {
                System.out.println(a);
            }
        }

Aucun commentaire:

Enregistrer un commentaire