TextButton Class
TextButton class is used to show simple text on the screen. You do not need to specify image for this object. What is required is to specify Paint instance with typeFace object.
Example:
var newGame = new TextButton({
text : "Start new game",
x : System.width / 2,
paint : res.paints.buttonText,
width : System.width / 2,
height : System.height / 2,
});
newGame.onClick = function()
{
// onClick event
}
this.add(newGame);
Methods
draw
(
protected
canvas
Draw the button. It is usally no need to overwrite this method, but it is possible to overwrite it to customize button appearance.
Parameters:
-
canvas
Canvas
init
() protected
Object initialisation. This method is called from class constructor and can be used in overwritten classes as a class constructor.
Properties
color
Integer
Color of the text. The color is in hexadecimal format for four chanels: alpha, red, green and blue.
black : 0xff000000;
white : 0xffffffff;
red : 0xffff0000;
green : 0xff00ff00;
transparent : 0x00000000;
Example:
// create a button
var button = new TextButton({
text : "Start new game",
paint : new Paint(),
color : 0xff0000ff,
...
});
paint
Paint
Instance of Paint class used to draw text. It specifies font size, color, typeface and also other graphics effects.
Example:
// create an instance of Paint class
var paint = new Paint();
paint.color = 0xff7DFAFF;
paint.textSize = System.width / 20;
// create a button
var button = new TextButton({
text : "Start new game",
paint : paint,
...
});
text
String
Text of the button.
Example:
var newGame = new TextButton({
text : "Start new game",
x : System.width / 2,
paint : res.paints.buttonText,
width : System.width / 2,
height : System.height / 2,
});
textSize
Integer
Set size of the font used in the button;
Example:
// create a button
var button = new TextButton({
text : "Start new game",
paint : new Paint(),
color : 0xff0000ff,
textSize : 11,
...
});