cocos2d-usage-guide

Cocos2d Icon cocos2d usage guide

Cocos2D Getting Started

WarpClient provides an interface for applications to interact with the cloud services. It allows client side applications to connect, subscribe and manage server side rooms, lobbies and users. The APIs are developed to be used asynchronously, which means you simply add the corresponding request listeners to the WarpClient instance to receive responses and updates. This page describes to how to set up your connection with the cloud server and introduces API usage.

AS3 API Reference

In order to use the various functions available, you will have to initialize and connect the instance of WarpClient. WarpClient is initialized by passing the apiKey and secretKey which you received after creating an app from AppHq (App42 management console).

[WarpClient initWarp:@"Your api key" secretKey:@"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
  • Chat Request Listener
  • Update Request Listener
  • Notification Listener
WarpClient *warpClient = [WarpClient getInstance];
[warpClient addConnectionRequestListener:connectionListener];
[warpClient addZoneRequestListener:connectionListener];
[warpClient addRoomRequestListener:roomListener];
[warpClient addNotificationListener:notificationListener];

The connection request listener callback will be invoked once the connection with the Warp server has been established. Note that two users can not be connected to the online application simultaneously. Here is a simple implementation of a request listener

#import < Foundation/Foundation.h >
@interface ConnectionListener : NSObject < ConnectionRequestListener >
@end
#import "ConnectionListener.h"
@implementation ConnectionListener
-(void)onConnectDone:(ConnectEvent*) event
{
    if (event.result==0)
    {
        NSLog(@"connection success");
        [[WarpClient getInstance] joinRoom:@"RoomId"];
    }
    else
    {
        NSLog(@"connection failed");
    }
}
-(void)onDisconnectDone:(ConnectEvent*) event
{
    NSLog(@"On Disconnect invoked");
}

Once you have supplied all the listeners you have to call the connectWithUserName() method of WarpClient to connect to the AppWarp server and join the Zone by giving in the user name as a parameter with which the client wishes to join the online application.

[[WarpClient getInstance] connectWithUserName:@"Jonny"];
Once you have successfully joined, you can either join the lobby or join a particular room. You should also subscribe the lobby or the room joined to catch the notifications generated in that particular room or lobby
[[WarpClient getInstance] joinRoom:@"RoomId"];
[[WarpClient getInstance]subscribeRoom:@"RoomId"];

To exchanges messages you can either send messages in plain text format using sendChat method or send encrypted data using sendUpdatePeers method respectively. To catch the messages sent through sendChat method, use the onChatReceived method of MyNotificationListener and to catch the data sent through sendUpdatePeers method, use the onUpdatePeersReceived method of MyNotificationListener.

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.