QNA > C > Come Si Può Iniziare A Sviluppare Giochi Multiplayer Per Android?

Come si può iniziare a sviluppare giochi multiplayer per Android?

WarpClient fornisce un'interfaccia per le applicazioni per interagire con i servizi cloud. Permette alle applicazioni lato client di connettersi, iscriversi e gestire stanze, lobby e utenti lato server. Le API sono sviluppate per essere utilizzate in modo asincrono, il che significa che è sufficiente aggiungere i corrispondenti ascoltatori di richieste all'istanza di WarpClient per ricevere risposte e aggiornamenti. Questa pagina descrive come impostare la connessione con il server cloud e introduce l'uso delle API.

Per utilizzare le varie funzioni disponibili, è necessario inizializzare e connettere l'istanza di 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.

Di Melba

Perché ci sono così pochi giochi multiplayer su iOS e Android? :: Cos'è un codice bancario e dove lo trovo?
Link utili