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 make shortly. Following the if
statement, call super.update()
so that the functionality of the parent class will still execute.
To finish the class off, we just have to make the onPlayAgain
function:
private function onPlayAgain...