Casa > C > Como Se Pode Começar A Desenvolver Jogos Multiplayer Para Android?

Como se pode começar a desenvolver jogos multiplayer para Android?

WarpClient fornece uma interface para aplicativos interagirem com os serviços da nuvem. Ele permite que aplicativos do lado do cliente se conectem, assinem e gerenciem salas do lado do servidor, lobbies e usuários. As APIs são desenvolvidas para serem utilizadas de forma assíncrona, o que significa que você simplesmente adiciona os ouvintes da solicitação correspondente à instância WarpClient para receber respostas e atualizações. Esta página descreve como configurar sua conexão com o servidor em nuvem e introduz o uso da API.

A fim de usar as várias funções disponíveis, você terá que inicializar e conectar a instância do WarpClient. WarpClient is initialized by passing the apiKey and secretKey which you received after creating an app from AppHq (App42 management console).

view plaincopy to clipboardprint ?

  1. WarpClient.initialize("Your API Key", "Your Secret Key");

After initialization, it is recommended that you implement and add a request listeners which will be called by WarpClient with the result of the requests. WarpClient comprises different listeners for different type of requests namely

  • Connection Request Listener
  • Lobby Request Listener
  • Zone Request Listener
  • Room Request Listener
  • Notification Listener
  1. WarpClient myGame = WarpClient.getInstance();
  2. myGame.addConnectionRequestListener(new MyConnectionListener());
  3. myGame.connectWithUserName("Jonathan");

The connection request listener callback will be invoked once the connection with the Warp server has been established with the given username. If this is successful, you can go ahead and call the room/lobby APIs of your app zone. Note that two users can not be connected to the online application simultaneously. Here is a simple implementation of a request listener.

  1. public class MyConnectionListener implements ConnectionRequestListener{
  2. @Override
  3. public void onConnectDone(ConnectEvent event) {
  4. if(event.getResult() == WarpResponseResultCode.SUCCESS){
  5. System.out.println("yipee I have connected");
  6. }
  7. }
  8. @Override
  9. public void onDisconnectDone(ConnectEvent event) {
  10. System.out.println("On Disconnected invoked");
  11. }
  12. @Override
  13. public void onInitUDPDone(byte paramByte) {
  14. // TODO Auto-generated method stub
  15. }
  16. }

addZoneRequestListener : Add your listener object on which callbacks will be invoked when a response from the server is received for Zone level requests like create/deleteRoom, User requests etc.

  1. public void addRoomRequestListener(RoomRequestListener listener)

addLobbyRequestListener : add your listener object on which callbacks will be invoked when a response from the server is received for Lobby requests like join/leaveLobby, subscribe/unsubscribeLobby and getLiveLobbyInfo.

  1. public void addLobbyRequestListener(LobbyRequestListener listener)

addNotificationRequestListener : add your listener object on which callbacks will be invoked when a notification is received from the server for any resource that has been subscribed to.

  1. public void addNotificationListener(NotifyListener listener)

Result Codes : These can be retrieved when an event callback is invoked from the event instance.

  1. byte SUCCESS = 0;
  2. byte AUTH_ERROR = 1;
  3. byte RESOURCE_NOT_FOUND = 2;
  4. byte RESOURCE_MOVED = 3;
  5. byte BAD_REQUEST = 4;
  6. byte CONNECTION_ERR = 5;
  7. byte UNKNOWN_ERROR = 6;
  8. byte RESULT_SIZE_ERROR = 7;

Appwarp also allows you to set custom data for users and rooms through the methods setCustomUserData() and setCustomRoomData(). To retrieve the custom data and other information WarpClient comprises getLiveUserInfo() and getLiveRoomInfo() methods.

De Hjerpe Schan

Se um humano comesse cocó, o que realmente aconteceria? :: O Samsung S9 Plus é seguro? O que é o Knox?