I am creating a Java game with libgdx. Really liking the engine so far but I noticed an issue when dragging the game window. Rendering seems to stop (which is okay) but I cant find any events that get called during this state. Is there any way I can trap it? It not a big deal for rendering as I cap the deltaTime, but for input the keyUp events don't get fired which messes up my movement code for the player (if you are to release the keys while dragging the window). Is there anything I can do? Thanks!
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
The problem you describe lies in the native window implementation of the LWJGL Display: This lightweight window does not loose focus while it is being moved around. Therefore calling
while moving the window around will still return true, even though the display is no longer updated.
I have found a workaround for this problem that works for my own project. One can add a parent Canvas to the LWJGL Display by calling
With this approach one is able to listen to window events by listening to the parent class. Adding a parent canvas to the display is also, what LwjglApplet does, so one is able to run libgdx applications inside an applet.
I have written an LwjglFrame class, that does essentially follow the same approach as LwjglApplet, with the difference, that the canvas is added to a JFrame:
With this class, one is able to run libgdx inside a JFrame and then listen for ComponentEvents. Here is some example code for how to create an LwjglFrame and pause the game, whenever the frame is moved around:
The downside of this approach is, that one needs some dedicated pause state, that gets entered once the window is moved. This pause state must then be manually exited by the user to continue the game. The upside is, that even if one does not pause the game, the screen will at least get updated, while one is moving the window (other than when using the lwjgl native frame).
I have not yet found a reliable way, to pause the game only during movements of the window, and automatically continue the loop once the movement is finished. The problem here is, that JFrame is not sending on/off events for moving the frame, but instead continuously notifies movement events while a window gets moved around.
EDIT
You could also make your com.badlogic.gdx.Game implement ComponentListener:
Then you create your Game like this: