Game Development Reference
In-Depth Information
All updates regarding friends are received via the
onFriendUpdate
. We first
examine the type of update received by switching on the status parameter.
A status value of
F_ACCEPT
indicates that another player accepted our friend request.
At this point, we need to update the player display so as to remove the friend circle
sprite. In addition, we need to add a new friend display.
For a status value of
F_REJECT
, there is no screen update required; however, a
subclass may inform the player of the fact.
A status value of
F_BREAK
means an existing friendship was dissolved. In this case,
we remove the corresponding friend display sprite and also update the player
display sprite to again add the make friend circle button.
PulseUI incorporates a visual hint as to whether a friend is online or offline; the
server automatically sends notification whenever the status value is either
F_ENTER
when a friend enters the game or
F_EXIT
when a friend leaves the game. We simply
find the corresponding player display and redraw it. Update is called with status
F_ENTER
and also in the case when a player enters the game for the first time, and for
each friend the player has, the client will receive an
F_ENTER
, even though the friend
may be offline. The sure way of finding out if the player is online is by calling the
method,
isFriendOnline
, on the GameClient API.
The following screenshot shows the visual hint. When the player is online, a shadow
filter is added to the friend sprite. In the screenshot, we observe that
Tony
is friends
with
Wilson
and
Jessie
, and
Jessie
is online.