4.6 Libgdx thread introduction, 4.6libgdx thread
All ApplicationListener methods are called in the same thread. This thread is a rendering thread that can call OpenGL. For most games, the update logic or rendering are generally placed in the ApplicationListener. render () method.
Any image operation will be performed in the rendering thread, and creation in other threads will lead to undefined behavior, Because OpenGL context is only available in the rendering process.
To transfer data from other threads to the rendering process, we recommend that you use Application. postRunnable (). This will enable the code to run at the next frame of the rendering process, before ApplicationListener. render () is called. New Thread (new Runnable (){
@ Override
Public void run (){
// Synchronize the required operations to the rendering thread.
Final Result result = createResult ();
// Push Runnable to the rendering thread.
Gdx. app. postRunnable (new Runnable (){
@ Override
Public void run (){
// Generate results
Results. add (result );
}
});
}
}). Start (); which Libgdx class is thread-safe?
In Libgdx, no class is thread-safe. Unless indicated in the official API. Remember, do not use multiple threads for any operations related to graphics and audio.
(Www.libgdx.cn is copyrighted. If you need to reprint it, indicate the source)