Game Development Reference
In-Depth Information
The systemTitle function definition
The systemTitle function sets up the display of the title screen and then jumps to a common state
used for all button clicks that close the BasicScreen windows ( STATE_SYSTEM_WAIT_FOR_CLOSE ).
We have not looked at the set of functions that control the STATE_SYSTEM_TITLE ,
STATE_SYSTEM_INSTRUCTIONS , SYSTEM_LEVEL_IN, and STATE_SYSTEM_GAME_OVER states in detail yet,
so let's do that now. There are two basic screen types represented:
Those that wait for a click of the OK button: titleScreen , instructionsScreen , and
gameOverScreen
Those that wait a predefined time to display the screen before moving on:
levenInScreen
First, we add an event listener to listen for the OK button clicked event to call the
okButtonClickListener function that is shared among all of the screens. After that, we switch the
systemState to the constant STATE_SYSTEM_WAIT_FOR_CLOSE . We then set the nextSystemState to
be called after okButtonClickListener is fired off.
This the first use for one of the three custom event classes we will create:
titleScreen.addEventListener(CustomEventButtonId.BUTTON_ID,
okButtonClickListener,false, 0, true);
All of the BasicScreen instances share the same okButtonClickListener function. The custom
event passes the id value of the BasicScreen instance to this listening function. The id value is
used to determine which screen the button was on and then moves the state machine to a new
state based on this evaluation.
The systemTitle , systemInstructions , and systemGameOver functions all look very similar. We'll
take a look at those in a bit. First, let's examine the waitForclose and okButtonClickListener
functions.
The systemWaitForClose function definition
The systemWaitForClose() function is associated with the STATE_SYSTEM_WAIT_FOR_CLOSE state. It
simply does nothing until the OK button on a screen is clicked.
This is the simplest function that you will encounter in this topic. It does absolutely nothing! It is
just a placeholder that the game loop can call while waiting for the OK button to be clicked.
The okButtonClickListener function definition
The okButtonClickListener function is used to determine what to do when an OK button on one
of the various BasicScreen instances is clicked. It switches to the nextSystemState when
complete.
This “listener” function is only fired off when it receives a CustomEventButtonId.BUTTON_ID event.
No matter which OK button was clicked (on any of the three screens that we will define with them),
we remove the event listener before we change state. Even though the same listener is used for
both the title and the instructions screens (for example), and we remove it from the title screen
before adding it again in the systemInstructions function. We do this to be sure we never have
extra listeners hanging around. Unused listeners waste memory and can slow down processing.
Search WWH ::




Custom Search