I have no idea how to approach this. I need to write a serializer for an Array<>
object found in libgdx.
public static void initialize(Server server) {
Kryo kryo = server.getKryo();
kryo.register(ServerData.class);
kryo.register(PlayerNick.class);
kryo.register(MoveLeft.class);
kryo.register(MoveRight.class);
kryo.register(MoveUp.class);
kryo.register(MoveDown.class);
kryo.register(StandUp.class);
kryo.register(ButtonLeft.class);
kryo.register(ButtonRight.class);
//
kryo.register(PlayerData.class);
kryo.register(Vector2.class);
kryo.register(Array.class);
kryo.register(PlayerDataPacket.class);
}
public static void initialize(Client client) {
Kryo kryo = client.getKryo();
kryo.register(ServerData.class);
kryo.register(PlayerNick.class);
kryo.register(MoveLeft.class);
kryo.register(MoveRight.class);
kryo.register(MoveUp.class);
kryo.register(MoveDown.class);
kryo.register(StandUp.class);
kryo.register(ButtonLeft.class);
kryo.register(ButtonRight.class);
//
kryo.register(PlayerData.class);
kryo.register(Vector2.class);
kryo.register(Array.class);
kryo.register(PlayerDataPacket.class);
}
public static class PlayerData {
public String name;
public int id;
public Vector2 position;
}
public static class PlayerDataPacket {
public Array<PlayerData> playerList = new Array<PlayerData>();
}
That's how my usual serialization is done. Here, I need to write a custom serializer for PlayerDataPacket
.
I have found this: https://groups.google.com/forum/#!topic/kryonet-users/9z4Ix2JO7JA
but it seems to be outdated since it can't find a few methods, plus it doesn't say how to do it with Array<>
.
I wrote an example for sending a float array over the network here using KryoNet:
https://stackoverflow.com/a/24339801/2413303