Game Development Reference
In-Depth Information
It defines three properties. The x and y coordinates determine the position of the circle
on the screen. The color property will determine the color of the game state sprite.
Adding a new game state
In Hello World, we add a game state by clicking on the Add button. For this, we
need to handle the mouse click as follows:
private function addGS(e:Event):void {
// Add button was clicked!
var newGS:HelloGameStateClient;
newGS = new HelloGameStateClient();
newGS.setX(300);
newGS.setY(300);
PulseGame.getInstance().
getGameClient().addGameState(newGS);
}
We simply create an instance of the game state, set the properties, and call the
addGameState API. Note that we don't add the circle to the screen yet. We wait for
the server's response.
When the clients receive the callback for adding game state, we update the screen
with a circle as follows:
public function onAddGS(newGS:GameStateClient):void {
// Received from server
var gs:HelloGameStateClient;
gs = newGS as HelloGameStateClient;
newGameState(gs);
}
private function
newGameState(gameState:HelloGameStateClient):void {
// Create and show a corresponding
// sprite for the game state
var s:Sprite = new GameStateSprite(gameState);
m_gs.put(gameState.getId(), s);
s.addEventListener(MouseEvent.MOUSE_DOWN,
mouseDownHandler);
s.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);
s.x = gameState.getX();
s.y = gameState.getY();
addChild(s);
}
 
Search WWH ::




Custom Search