O'Reilly logo

Haxe Game Development Essentials by Jeremy McCurdy

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Adding menu sounds

Next, we're going to handle playback of our whoosh, ting, and click sound effects. These will be used on both the title screen and the level-end screen.

Creating playback functions

To start, let's build the functions to play our sound effects. We'll start with the whoosh sound that will play when the star on the title screen and header on the level end screen tween in.

In SoundManager, add this function:

public function playWhooshSound(delay:Float):Void {
  var timeout:Float = 1;
  FlxTween.num(timeout, 0, delay, { complete:function(tween:FlxTween) {
      FlxG.sound.play(Sounds.SOUND_WHOOSH,Sounds.VOLUME_WHOOSH);
    } 
  });
}

This function takes in a float value that will be used to delay playback of the sound effect. This will allow us to sync ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required