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

Restarting the level

Next, we'll make it so that the level will restart when the player clicks anywhere on screen.

To do this, we'll have to add an update function:

  override public function update():Void
  {
    if (FlxG.mouse.justReleased)
    {
      onPlayAgain();
    }
    super.update();
  }

This function will override the update function of the FlxState parent class, which is why we use the override keyword in this case.

Inside the function, we make an if statement to check if FlxG.mouse.justReleased is true. This is another way to handle mouse input in HaxeFlixel and we're doing it this way because we just want to know when the player clicks anywhere on screen, instead of on a particular thing.

Inside the if statement, we'll call an onPlayAgain function, which we'll ...

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