Basically, I use Stencyl engine to make games. The engine uses Haxe and doesn't support everything that Haxe supports.
I want to manipulate he android 'back button' press. Stencyl supports code mode where I can write a haxe code. I wanted to overwrite android's default back button press. When player is playing the game, if he press back button, the game goes to background. Instead, I want the level to restart when backbutton is pressed. Can this be accomplished with any available source for Haxe?
I tried searching for any code help but can't find one. That's why messaging here. Appreciate any help.
P.S: Stencyl developer may not be a real developer for you. If that's the case, I'm not a developer. I'm just someone who uses all the resources to achieve what I want. So please avoid such topics which isn't going to help anybody.
You could try below code
Lib.current.stage.addEventListener(openfl.events.KeyboardEvent.KEY_UP, checkKeypress);
...
private function checkKeypress(e:openfl.events.KeyboardEvent):Void
{
switch (e.keyCode)
{
case openfl.ui.Keyboard.ESCAPE:
e.stopImmediatePropagation();
restartLevel();
}
}
private function restartLevel():Void
{
//your code to restart level here
}