Game Development Reference
In-Depth Information
offColor : The background color of the button when the mouse is not hovering over it
overColor : The background color of the button when the mouse is hovering over it
positionOffset : The movement buffer to bump the text from the left side of the button
after it is drawn, which is useful with some fonts when positioning the text properly.
The setDisplayText function definition
This function is used to reset the displayText.text to a new value if needed. It accepts in a
single string parameter, text , and changes out displayText.text with the new value. This is
useful for setting the levelInScreen text to display the game level number on each new level.
The button listener function definitions
The BasicScreen class needs to respond to the click , over , and off events created in the
createOkButton function of the BasicScreen class. We do this by creating this set of three listener
functions:
OkButtonClickListener : This event dispatches a CustomEventButtonId instance and
passes the id variable value back to the listeners. In the GameFrameWork class, we have
set up a listener for this event.
okButtonOverListener : This event calls the changeBackGroundColor function of the
SimpleBlitButton and passes in the constant OVER . The SimpleBlitButton will respond
by changing the color of the button to the OVER color.
okButtonOffListener : This event calls the changeBackGroundColor function of the
SimpleBlitButton and passes in the constant OFF . The SimpleBlitButton will respond
by changing the color of the button to the OFF color.
The SimpleBlitButton class
The SimpleBlitButton class is used to create very simple UI buttons that have only a background
color (two actually, one for OFF and one for OVER states), and a text label. It uses BitmapData to
create the background and a Bitmap instance holder for this BitmapData instance. It is called a blit
button because we use a simple blitting technique of swapping out the BitmapData reference on
the bitmap when we want to change the color of the button. Also, we draw the text for the button
into a BitmapData to demonstrate the use of BitmapData for dynamically created display object.
The terms “blitting” or “to blit” come from the classic game development method of moving bits of
data around in memory very fast. In some cases, the bits moved with this technique were referred
to as sprites, player missile graphics, blobs, or any other number of machine-specific terms. We
use “blitting” to mean painting the screen or the contents of a Bitmap instance with BitmapData in
various ways.
Create the SimpleBlitButton.as file in the framework package structure we created earlier:
/source/classes/com/efg/framework/SimpleBlitButton.as
Here is entire code listing for this class:
package com.efg.framework
{
import flash.display.Bitmap;
Search WWH ::




Custom Search