I would like to stop the game when the exported game's window loses focus. I tried to add a listener to the window's focused property, but it does not seem to fire.
Note: I have confirmed that the window variable is not null when run in an exported game. The code to stop the game when focus is lost is still not working, though.
The getWindow() method looks as follows:
The getField method simply retrieves the specified field's value using reflection.
Any help is appreciated.
Window window = ripper.getWindow();
if (window == null)
return;
ChangeListener<Boolean> listener = (observable, oldValue, newValue) ->
{
if (!newValue)
Greenfoot.stop();
};
window.focusedProperty().addListener(listener);
WorldHandlerDelegateStandAlone delegate = getStandaloneDelegate();
if (delegate == null)
return null;
GreenfootScenarioViewer viewer = getField("viewer", delegate);
WorldDisplay world = getField("worldDisplay", viewer);
ImageView imageView = (ImageView)world.getImageView();
return imageView.getScene().getWindow();
