Game Development Reference
In-Depth Information
The following is the code that handles the notification sent by the server for a
friend request. The code is handled in PulseGame. The following callback method
is implemented, which simply accepts the friend request. In our subclass of
PulseGame, we may want to inform that a request was received, and accept or
reject the request based on the player's response.
public function onMakeFriend(newFriend:GameAvatarClient):void {
m_netClient.respondToFriendInvite(true, newFriend.getName());
}
PulseGame also handles all the updates regarding friends:
public function onFriendUpdate(status:int,
errorCode:int,
aFriend:GNetFriend):void {
switch(status) {
case GameConstants.F_ACCEPT:
// new friend, create a new FriendDisplay
var av:GameAvatarClient;
av = aFriend.getAvatar() as GameAvatarClient;
m_friendsDisplay.addFriend(aFriend);
m_playersDisplay.updatePlayer(av.getId());
break;
case GameConstants.F_REJECT:
// player rejected friendship :(
// inform the player..
break;
case GameConstants.F_BREAK:
// no longer friends, anymore! :( remove the FriendDisplay
m_friendsDisplay.removeFriend(aFriend.getId());
m_playersDisplay.updatePlayer(aFriend.getAvatar().getId());
break;
case GameConstants.F_ENTER:
case GameConstants.F_EXIT:
// Friend came online, update the FriendDisplay
// Friend went offline, update the FriendDisplay
m_friendsDisplay.updateFriend(aFriend);
break;
}
}
 
Search WWH ::




Custom Search