Class: Label

Label()

A Label draws text on the canvas of a Game.
Labels must be added to Groups, similar to Sprites, to appear in a Game.

Constructor

new Label()

Initialize default values for all properties.
Source:

Methods

addAction(action)

Add an Action to this object: a special function that will be automatically applied over time until it is complete.
Most common actions can be created with the static methods in the ActionFactory class.
All actions added to this object are performed in parallel, unless enclosed by a Sequence action.
Parameters:
Name Type Description
action Action an action to be applied to this object
Source:

destroy()

Remove this sprite from the group that contains it.
Source:

draw(context)

Draw the label on a canvas, using the style properties specified by this object.
Parameters:
Name Type Description
context the graphics context object associated to the game canvas
Source:

moveBy(dx, dy)

Change this sprite's position by the given amounts.
Parameters:
Name Type Description
dx number value to add to the position x coordinate
dy number value to add to the position y coordinate
Source:

setOpacity(opacity)

Change the opacity when drawing, enabling objects underneath to be partially visible by blending their colors with the colors of this object.
0 = fully transparent (appears invisible); 1 = fully opaque (appears solid)
Parameters:
Name Type Description
opacity number opacity of this object
Source:

setPosition(x, x, alignment)

Set the location of this label.
Parameters:
Name Type Description
x number the x coordinate of the text, corresponding to the location specified by the "alignment" parameter
x number the y coordinate of the baseline of the text
alignment string one of: "left", "center", "right"; determines what location of the text that the x coordinate refers to
Source:

setProperties(properties)

Set the style properties for displaying text.
Properties that can be set include:
  • fontName (string, e.g. "Arial Black")
  • drawBorder and drawShadow (boolean)
  • fontSize, borderSize, and shadowSize (number)
  • fontColor, borderColor, and shadowColor (string, e.g. "red" or "#FF0000")
Properties are specified with an object.
For example: { "fontSize" : 48, "fontColor" : "#8800FF", "drawShadow" : false }
Parameters:
Name Type Description
properties object an object containing property name and value pairs
Source:

setText(text)

Set the text displayed by this label.
Parameters:
Name Type Description
text string the text displayed by this label
Source:

setVisible(visible)

Set whether this sprite should be visible or not; determines whether sprite will be drawn on canvas.
Parameters:
Name Type Description
visible boolean determines if this sprite is visible or not
Source:

update(deltaTime)

Process any Actions that have been added to this Label.
Parameters:
Name Type Description
deltaTime number time elapsed since previous frame
Source: