Game Development Reference
In-Depth Information
In order to demonstrate the game state update, the Hello World sample allows the
players to drag the colored circle around within the game screen. For this, we need
to implement the mouse event handlers. The handlers also keep track of the
currently selected sprite. Here is the code for the mouse event handlers.
The mouse down handler will first figure out the sprite on which the click was made
and initiate the sprite drag.
private function mouseDownHandler(event:MouseEvent):void {
//trace("mouseDownHandler");
var sprite:Sprite;
sprite = Sprite(event.target);
sprite.addEventListener(MouseEvent.MOUSE_MOVE,
mouseMoveHandler);
sprite.startDrag();
}
When the mouse button is released we stop the mouse drag process. We also record
the final position of the sprite. We then get the corresponding game state associated
with the colored circle and send in the request to the server to modify the game state.
We also update the m_selected property.
private function mouseUpHandler(event:MouseEvent):void {
//trace("mouseUpHandler");
var sprite:GameStateSprite;
sprite = Sprite(event.target) as GameStateSprite;
// trace("x: " + sprite.x + " y: " + sprite.y);
sprite.removeEventListener(MouseEvent.MOUSE_MOVE,
mouseMoveHandler);
sprite.stopDrag();
var gs:HelloGameStateClient;
gs = sprite.m_gs;
if ( gs != null ) {
gs.setX(sprite.x);
gs.setY(sprite.y);
PulseGame.getInstance().
getGameClient().updateGameState(gs);
}
setSelected(sprite);
}
This concludes the walk-through of the Hello World sample. The readers are
encouraged to study the sample from the downloaded package and give it a test drive.
 
Search WWH ::




Custom Search