I try to develop a game for Android platform, using Libgdx library. For network, I use the Kryonet library.
I want to change screen when I'm sure that my application is connected to my server.
The network part seems work but I have a problem with threads: it's the Kryonet's thread which execute OpenGL, not the Libgdx thread:
public class MyGdxGame extends Game {
public static int UDP_PORT = 55555, TCP_PORT = 55556;
private Client client;
@Override
public void create() {
/*
* client connection
* etc ...
*/
client.addListener(new Listener() {
private int nb = 0;
@Override
public void received(Connection connection, Object data) {
super.received(connection, data);
nb++;
if (nb == 5) {
MyGdxGame.this.setSecondScreen();
}
}
});
setScreen(new First(this, client));
}
protected void setSecondScreen() {
setScreen(new Second(this, client)); //This part should be executed by Libgdx thread ?!
}
Note that First and Second are both Screen class which just draw an image.
I have this exception when I try to launch Second Screen: Exception in thread "Client" java.lang.RuntimeException: No OpenGL context found in the current thread.
Can I force the LibGDX thread to execute instructions ? Is an other approach possible?
Thank's Jonathan