Game Development Reference
In-Depth Information
We create an instance of a GameStateSprite class with the properties of the received
game state and add it to the screen. We also set up the mouse listeners in order to
implement dragging.
It is important to know that the ID property of a game state should be zero during
addition. After the server validates the new game state, it will assign a unique ID to
the game state and return it in the add notification. After creating a new sprite for
the game state, we will add the sprite to a hash table for easy access, and for later
processing during update and remove.
Note that the client receives the update from the server; the PulseGame is set up to
be the callback handler. The HelloGame—the sub-class of PulseGame—overrides
the onNewGameState , and the implementation of this will call the HelloGameScreen's
onAddGS method. This flow is the same for all game state notifications received from
the server.
The following is the simple delegation in HelloGame class:
public override function
onNewGameState(gameState:GameStateClient):void {
(m_gameScreen as HelloGameScreen).onAddGS(gameState);
}
Updating game state
The mouse handlers are listed below. During the mouse up event, we retrieve the
game state that the circle sprite represents and call the updateGameState API.
private function mouseDownHandler(event:MouseEvent):void {
//trace("mouseDownHandler");
var sprite:Sprite;
sprite = Sprite(event.target);
sprite.addEventListener(MouseEvent.MOUSE_MOVE,
mouseMoveHandler);
sprite.startDrag();
}
private function mouseUpHandler(event:MouseEvent):void {
//trace("mouseUpHandler");
// get the GameStateSprite which was dragged.
var sprite:GameStateSprite;
sprite = Sprite(event.target) as GameStateSprite;
//trace("x: " + sprite.x + " y: " + sprite.y);
sprite.removeEventListener(MouseEvent.MOUSE_MOVE,
mouseMoveHandler);
sprite.stopDrag();
 
Search WWH ::




Custom Search