Game Development Reference
In-Depth Information
Figure 2-1.
The Super Click screenTitle with the OK button
The createOkButton function definition
If the
BasicScreen
instance is to have a button used to move the state machine on to the next
systemState
, it can be added with the public
createOkButton
function. This function actually does
quite a bit. First, it creates an instance of the
SimpleBlitButton
framework class (we will dig into
this class next). The
SimpleBlitButton
class takes some parameters into its constructor and then
uses them to create a button with
OVER
and
OFF
states.
OVER
occurs when the mouse is placed
over the button, and
OFF
is the default state when the cursor is not on the button. For our simple
basic screens, we are going to have a single, reusable OK button. It will have black text on a white
background in the
OFF
state and the same black text but on a red background for the
OVER
state.
The function then adds event listeners for the mouse events on the
okButton
SimpleBlitButton
instance.
The parameters passed into this function follow:
text
: The actual text to put on to the button
location
: A
Point
class instance that will be used to define the
x
and
y
values for the
upper left-hand corner for the
okButton SimpleBlitButton
width
: The width of the button
height
: The height of the button
textFormat
: The
TextFormat
of the button text