Game Development Reference
In-Depth Information
The
start
method then initiates the following series of method calls. First it
instantiates the
GameClient
, the main API class of Pulse, which enables all
communication with the server. This method must be overridden if the game defines
a schema, which is true in most cases. The login screen is then initialized so that it
can create any sprites that are needed for display, and finally makes a call to display
the login screen to the player.
In the case of advanced implementation of a game, the
showLogin
method may be
overridden to read parameters passed from the HTML embedded code into the Flash
game
swf
. In some cases, the game may not show the login screen, but retrieve the
username and session from the flash parameters and directly invoke the server login.
Upon the server's response to the login request, the Pulse SDK serves up a
GameLoginEvent
defined in the Pulse layer. The login event callback,
onLogin
method, is called. The login event passed in may be examined to determine if the
login was successful or returned an error.
The following is the default implementation that you may find in
PulseGame
:
protected function onLogin(event:GameLoginEvent):void {
if ( event.isSuccess() ) {
init(); // init the game client screen
m_timer.addEventListener(TimerEvent.TIMER,
processMsg);
m_timer.start();
}
else {
var loginError:int = event.getErrorCode();
if ( loginError == GameErrors.ERR_LOGIN_FAIL ) {
// try again
}
else {
// Server un-available!!
}
}
}