Game Development Reference
In-Depth Information
addChild(s);
}
When we receive a notification from the server that a game state was removed, we
simply remove the corresponding game state sprite from the screen.
public function onRemoveGS(gameState:GameStateClient):void {
// Received from server to remove a game state
var s:GameStateSprite;
s = m_gs.getValue(gameState.getId());
if ( s != null ) {
removeChild(s); // remove from screen
m_gs.remove(gameState.getId()); // remove from cache
}
}
We also make sure to remove it from the hash map.
When we receive a notification that a game state was updated, find the
corresponding game state sprite in the hash map and update the x and y from the
received updated game state:
public function
onUpdateGS(gameState:GameStateClient):void {
// An update game state was received from server
var gs:HelloGameStateClient;
gs = gameState as HelloGameStateClient;
var s:GameStateSprite = m_gs.getValue(gs.getId());
if ( s == null ) {
// This can happen when the player
// joins in the middle of the game
newGameState(gs);
}
else {
s.x = gs.getX();
s.y = gs.getY();
}
}
Now that we have handled the notification from the servers when a game state was
added, removed, or modified, how do we generate these game states in response
to player actions? Let us examine them now one by one. The player may add a new
game state by clicking on the Add button. The callback method that gets called when
the player clicks on the Add button is shown below:
private function addGS(e:Event):void {
// Add button was clicked!
var newGS:HelloGameStateClient;
newGS = new HelloGameStateClient();
 
Search WWH ::




Custom Search