Game Development Reference
In-Depth Information
addChild(buttonBackGroundBitmap);
addChild(buttonTextBitmap);
this.buttonMode = true;
this.useHandCursor = true;
}
public function changeBackGroundColor(typeval:int):void {
if (typeval == SimpleBlitButton.OFF) {
buttonBackGroundBitmap.bitmapData = offBackGroundBD;
}else {
buttonBackGroundBitmap.bitmapData = overBackGroundBD;
}
}
}
}
The class import and variable definition for the SimpleBlitButton class
The button we create is actually a Sprite container instance with two Bitmap layers. The
bottom layer is the buttonBackGroundBitmap . The bitmapData property of the
buttonBackGroundBitmap can be easily swapped between our offBackGroundBD and
overBackGroundBD BitmapData rectangles on rollover and rollout. The text portion of the button
is the top Bitmap layer. It will contain the buttonTextBitmapData BitmapData instance. We
create two constants to define these two basic states for the button:
public static const OFF:int = 1;
public static const OVER:int = 2;
We will create this button text in the constructor of the class. The buttonTextBitmapData text is
drawn into a BitmapData instance for display. While we could simply use TextField directly in the
Sprite button, we are focusing on games in this topic. Because of this, we want to show an early
use of Bitmaps and BitmapData for animation. We will focus on this simple blit technique, because
we want to introduce a use of bitting animation early in this section. The more you are familiar
with the various uses of BitmapData , the more comfortable you will be as we progress through the
rest of the chapters.
We have one other variable to define in this section. It is used to “bump” the text position back to
the upper left-hand corner of the button if needed. With some fonts you might find that the text on
the button has been truncated to the right. The positionOffset variable can be set in the
constructor to help mitigate this issue.
The constructor definition for the SimpleBlitButton class
The constructor function for the SimpleBlitButton class accepts in the parameters necessary for
creating the correct size, colors and text for the Button and its two states: OFF and OVER .
This constructor for the SimpleBlitButton accepts these parameters:
x value screen placement
y value screen placement
width of the button
Search WWH ::




Custom Search