Game Development Reference
In-Depth Information
Implementing the game screen
The HelloGameScreen is subclassed from GameScreen defined in PulseUI package.
We will add two buttons for adding and removing game states from the game
instance. Like other subclassing where we will need to override the specific methods,
the PulseUI framework will take care of calling them at the right time. For example, the
init method is overridden to initialize any sprites that you may need during the game,
the show method must be overridden to actually put the sprites onto the screen, and
finally, the hide method should be overridden to remove them from the screen.
Note that the init method is called once, but the show and hide may be called several
times, that is every time when the player enters or leaves the game room.
Here is a partial listing of the class that shows the property definitions, and the
overriding of the init, show, and hide methods:
public class HelloGameScreen extends GameScreen
{
private var m_addBtn:Button;
private var m_removeBtn:Button;
private var m_gs:Map = new Map();
// keep track of selected.
private var m_selected:GameStateSprite;
public function HelloGameScreen()
{
super();
}
public override function init():void {
super.init();
initBtns();
}
public override function show():void {
super.show();
var gc:GameClient;
gc = PulseGame.getInstance().getGameClient();
// If the game has already started, add the buttons
if ( gc.getMyGameRoom().getRoomStatus() ==
GameConstants.ROOM_STATE_PLAYING ) {
addChild(m_addBtn);
addChild(m_removeBtn);
}
}
public override function hide():void {
// Remove all the sprites and cleanup
var states:Array = m_gs.values();
for ( var i:int=0; i<states.length; i++ ) {
 
Search WWH ::




Custom Search