UITextButton
class UITextButton extends UIBaseElement
This is a basic base text button which you can use in your Game UI.
Constructor
new UITextButton(x: number, y: number) → {}
A Bitmap Text Button with an outlined background border, filled with background color. It uses a RoundRect as background and changes the background color on hovering over. The background will be drawn with 0.5 opacity, so that the background of the button is slightly shining through.
// Create a new Button
class PlayButton extends UITextButton {
constructor(x,y) {
super(x,y, {
font: 'my-font',
text: 'Play',
// if you omit the next two, size is calculated by the size of the text
borderWidth: 200,
borderHeight: 20,
backgroundColor: '#00aa0080',
hoverColor: '#00ff00ff'
});
}
onClick(){
state.change(state.PLAY);
}
}
world.addChild(new PlayButton(15,200));
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
x | number |
x pos of the button |
||
y | number |
y pos of the button |
||
settings.font | string |
<optional> |
The name of the BitmapText font to use |
|
settings.size | number |
<optional> |
1 |
The scale factor of the BitmapText |
settings.text | string |
<optional> |
The text to display |
|
settings.bindKey | string |
<optional> |
The key to bind the action to (default: none) |
|
settings.hoverOffColor | string |
<optional> |
"#00aa0080" |
The css value of a color to be used if the pointer is not hovering over the button |
settings.hoverOnColor | string |
<optional> |
"#00ff00ff" |
The css value of a color to be used if the pointer hovers over the button |
settings.borderStrokeColor | string |
<optional> |
"#000000" |
The css value of a color to be used to draw the border |
settings.fillStyle | string |
<optional> |
The css value of a tint color to be used to tint the BitmapText |
|
settings.textAlign | string |
<optional> |
"center" |
horizontal text alignment |
settings.textBaseline | string |
<optional> |
"middle" |
the text baseline |
settings.borderWidth | number |
<optional> |
Width of the button |
|
settings.borderHeight | number |
<optional> |
Height of the button |
Summary
Properties from UITextButton
string |
|
BitmapText |
|
string |
|
string |
|
string |
|
string |
|
string |
|
Properties inherited from UIBaseElement
boolean |
|
number |
|
boolean |
|
boolean |
|
boolean |
|
boolean |
|
boolean |
|
Properties inherited from Container
boolean |
|
boolean |
|
Color |
|
boolean |
|
boolean |
|
boolean |
|
string |
|
Properties inherited from Renderable
number |
|
boolean |
|
Container | Entity |
|
ObservableVector2d |
|
boolean |
|
string |
|
Body |
|
Matrix2d |
|
number |
|
string |
|
boolean |
|
boolean |
|
boolean |
|
boolean |
|
boolean |
|
boolean |
|
boolean |
|
Rect | RoundRect | Polygon | Line | Ellipse |
|
string |
|
Function |
|
Application |
|
ObservableVector3d |
|
GLShader |
|
Color |
|
boolean |
|
Properties inherited from Rect
Methods inherited from UIBaseElement
boolean |
|
|
|
|
|
|
|
|
|
boolean |
|
Methods inherited from Container
Methods inherited from Renderable
Methods inherited from Rect
Rect |
|
Rect |
|
boolean |
|
Rect |
|
boolean |
|
boolean |
|
boolean |
|
Rect |
|
Rect |
|
Polygon |
|
Rect |
|
Methods inherited from Polygon
Array<number> |
|
boolean |
|
Polygon |
|
Polygon |
|
|
|
Polygon |
|
Polygon |
|
Polygon |
|
Public Properties
bitmapText: BitmapText
BitmapText
the bitmapText used by the UITextButton class
borderStrokeColor: string
string
The css value of a color to be used to draw the border
hoverOffColor: string
string
The css value of a color to be used if the pointer is nothovering over the button
hoverOnColor: string
string
The css value of a color to be used if the pointer hovers over the button
textAlign: string = "center"
string
Set the default text alignment (or justification),
possible values are "left", "right", and "center".
textBaseline: string = "middle"
string
Set the text baseline (e.g. the Y-coordinate for the draw operation),
possible values are "top", "hanging, "middle, "alphabetic, "ideographic, "bottom"