简体   繁体   中英

Gdx exit closing entire application - how to close only the gdx frame?

I have a game editor, in which it is possible to launch the game being edited in a separate window (but within the same VM). However, when the game is closed, I would like to close its gdx window, without bringing down the whole application (that is, the editor).

I am currently using the following code inside the JFrame that hosts the LwjglApplication :

public void windowClosing(WindowEvent e) {
    System.err.println("Now closing app...");
    Gdx.app.exit();
    System.err.println("App now closed.");
}

This prints the goodbye, closes the GDX window, and proceeds to terminate my VM. Any suggestions?

In the desktop (lwjgl backend) Gdx.app.exit() posts a Runnable that causes the loop mainLoop to complete and control to fall out the bottom of that function (see the source ). The mainLoop ends with :

if (graphics.config.forceExit) System.exit(-1);

The graphics.config is the LwjglApplicationConfiguration object passed in LwjglApplication constructor . So just set

config.exit = false

in the config object (you may need to create one and use a different constructor if you're not currently creating a config object). There are other handy things you can set in the config object, too.

(This code is from GIT, so things may be different in older version of GDX or with other backends.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM