Hello and thank you for taking the time to read my post.
In any of my State classes I simply use the following code to change to any of my desired game states.
/////////////////////////////////////////////////////////////////////////////////////
// FUNCTION: update()
//
// INFO: Overrides a method in BasicGameState.
public void update(GameContainer gc, StateBasedGame sbg, int delta) {
if (case)
{
sbg.enterState(x);
}
}
The issue arises for me when I’m trying to enter a new state based on a packet I have received from my server. For example, say I want a client to send login details to the server and if it those details are accepted, then the client will advance to the next state.
I figured this must be handled somewhere in my NetworkListener class (which is the listener object that is added to my Kryonet Client object) … but I don’t know how to make the “Slick World” hold hands with the “Kryonet world”.
/////////////////////////////////////////////////////////////////////////////////////
// FUNCTION: received()
//
// INFO: Inherits from class Listener.
// Called when an object has been received from the remote end of the connection.
// This will be invoked on the same thread as Client#update(int) and Server#update(int).
// This method should not block for long periods as other network activity will not be
// processed until it returns.
public void received(Connection con, Object obj) {
if (obj instanceof Packet.Packet1LoginAnswer) {
boolean answer = ((Packet.Packet1LoginAnswer) obj).isAccepted();
if (answer)
/* insert code here to enter state 2 */
}
Thank you!