By default, SimpleApplication
pauses the update loop whenever the window loses focus, that is, the player switches to another application. For multiplayer or real-time applications, pausing one of the players is not even an option. For such games, you need to deactivate the default pausing behavior in the simpleInitApp()
method:
Make a copy of
Main.java
and name the classFocusTest.java
. Remember to also refactor the first line of themain()
method toFocusTest app = new FocusTest();
.In
simpleInitApp()
, change the application behavior as follows:public void simpleInitApp() { setPauseOnLostFocus(false); }
In the
simpleUpdate()
loop, add the following sample code:public void simpleUpdate(float tpf) { rootNode.rotate(tpf,tpf,tpf); }
When you run the application, the blue cube rotates. When you switch to the desktop, the cube should continue rotating.
Remove the setPauseOnLostFocus()
line (or set it to true
) and run the sample again. When you switch to the...