Game Development Reference
In-Depth Information
newGS.setX(300);
newGS.setY(300);
PulseGame.getInstance().
getGameClient().addGameState(newGS);
}
When a player wishes to add a new game state, we simply create a new game state
object, initialize the properties, and call the Pulse API to add the game state. Upon
the server receiving the message, it will be broadcasted to all the players in the room,
including the one who sent it in the first place. This will result in the calling of the
method newGameState in all the players' rooms. So in effect, the colored circle is not
drawn until a notification is received from the server, including for the player that
created it.
The code below shows how the add and remove buttons are created and initialized.
This method is called from the init method, which we saw earlier:
private function initBtns():void {
m_addBtn = new Button();
m_addBtn.x = 200; m_addBtn.y = 150;
m_addBtn.height = 20; m_addBtn.width = 40;
m_addBtn.label = "Add";
m_addBtn.addEventListener(MouseEvent.CLICK, addGS);
m_removeBtn = new Button();
m_removeBtn.x = 250; m_removeBtn.y = 150;
m_removeBtn.height = 20; m_removeBtn.width = 80;
m_removeBtn.label = "Remove";
m_removeBtn.addEventListener(MouseEvent.CLICK, removeGS);
}
Similar to the add mechanics, the removal of a game state is triggered when
the player clicks on the remove button.
private function removeGS(e:Event):void {
if ( m_selected != null ) {
PulseGame.getInstance().
getGameClient().
removeGameState(m_selected.m_gs);
}
}
During the callback that is fired when the remove button is clicked, we check if there
is any selection of a colored circle. If so, we call the pulse API to remove the game
state. The server, on receiving the request, will broadcast to all the players in the
game room including the one sending the request. When the request is received by
the clients, the onRemoveGS method is called and the game state sprite gets removed
from the screen as shown above.
 
Search WWH ::




Custom Search