Game Development Reference
In-Depth Information
value representing a constant that we will define in the Main.as ( GameFrameWork.as child class).
The constant will be the id string name of the element on the scoreBoard to update. The value
variable passed will be a string representing the value to show on the scoreBoard for the
corresponding TextField . It's constructed to allow the Game class instance and its associated
classes to update the ScoreBoard class instance without having to maintain a reference to it. This
allows the Game and its associated classes to remain decoupled from the Main.as and the basic
framework classes. We will see the same thing with the levelInScreen a little later. Why is the
ScoreBoard part of the framework and not part of the Game class? We wanted to have the
ScoreBoard be part of the Main class game framework because the Game class instance is not the
only object that might interact with the ScoreBoard . We do not implement it in this simple example,
but the Main might have other data such as a system-held high score, links out, or even a frame
counter in the ScoreBoard .
Why decouple the scoreboard from the game class instance? It is true that we could make calls
directly to the ScoreBoard from Game by using the root or parent attribute of the Game class. While
this is certainly possible, if we decouple the Game class from the ScoreBoard class, then the Game
class will be reusable across multiple frameworks (even your own) with no need to use our
framework. The new framework would just need its own ScoreBoard or the Game would need to
implement its own.
The levelScreenUpdateListener function definition for
Main.as
The levelScreenUpdateListener allows the Game class to update the text on the levelInScreen .
Like the scoreBoardUpdateListener , the levelScreenUpdateListener function is used to pass
data from the Game class instance to the levelInScreen . When the Game class updates the level
value using its own newLevel function, the levelInScreen must also update its text so the correct
level number will be shown on the screen during the systemLevelIn function. The predefined
default String variable, levelIntext will be combined with the passed in value:
levelInScreen.setDisplayText(levelInText + e.text);
The gameOverListener function definition for Main.as
The gameOverListener listens for the Game.GAME_OVER simple custom event and then changes the
framework state accordingly.
When the Game class instance fires off the GAME_OVER simple custom event, the Main listens for it
and runs this function. It cleans up all of the game-related listeners by removing them and then
changes state to the STATE_SYSTEM_GAME_OVER state which was discussed earlier
The newLevelListener function definition for Main.as
The newLevelListener listens for the Game.NEW_LEVEL simple custom event and changes the state
accordingly.
The newLevelListener listens for the Game class instance to fire off the simple custom event,
NEW_LEVEL . It then changes the systemState to the STATE_SYSTEM_NEW_LEVEL state.
Search WWH ::




Custom Search