Game Development Reference
In-Depth Information
Processing messages from the server
Once the login is successful, in order to process the notifications received from the
server, the game code must repeatedly call handleMsg method. Usually in AS3
programming, events generated in one module can be handled and processed
by subscribing to the events via the event dispatch and listener model in another
parts of the software. In case of Pulse SDK, as you will learn throughout this topic,
the number of server notifications are one too many and becomes cumbersome to
program using the events model. For this reason, Pulse adopts an interface model
usually found in Java and C++ programming. In order to process the notifications
from the server, the developer must provide an implementation for the Pulse
callback interface, set up a timer and have it call handleMsg . For most games, calling
it every 100 ms would suffice. You could call it more often for racing types of games
where you would want to process any incoming messages as quickly as you can.
However, for turn-based games such as chess, calling it every second, or even two,
would be acceptable.
public function handleMsg():Boolean
The return value indicates if there are still pending messages in the queue. There
may be more than one message pending that needs to be processed. For each call to
the method, one message will be processed. The order of the message processed is
in the same order they were received from the server.
Based on the message type, the corresponding GameClientCallback interface
methods will be invoked on the object instance that you provided in the constructor.
Without calling this method, there will be no callback methods fired.
The programming API
For the rest of the chapter will go over some key APIs offered by the pulse package
and leave the discussion of PulseUI until the next chapter. A complete reference of
the API is provided in Appendix B .
The game implementation to communicate with the server and receive notification
from other player's action is via the following two classes:
• PulseClient
• PulseCallback
 
Search WWH ::




Custom Search