Moscrif API Docs for: 2012q3
Show:

TextButton Class

include "lib://game2d/textButton.ms";
Library: game2d

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);

Item Index

Methods

Methods

draw

(
  • canvas
)
protected

Draw the button. It is usally no need to overwrite this method, but it is possible to overwrite it to customize button appearance.

Parameters:

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,
    ...
});

height

Integer

Height of TextButton in pixels

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,
    ...
});

width

Integer

Width of TextButton in pixels