Class: BitmapText

BitmapText

A BitmapText object will create a line or multiple lines of text using bitmap font. To
split a line you can use '\n', '\r' or '\r\n' in your string. You can generate the fnt files using:

A BitmapText can only be created when the font is loaded

// in this case the font is in a file called 'desyrel.fnt'
var bitmapText = new BitmapText({
  text: "text using a fancy font!",
  font: "35px Desyrel",
  align: "right",
});

http://www.angelcode.com/products/bmfont/ for windows or
http://www.bmglyph.com/ for mac.


new BitmapText(text, style)

Parameters:
Name Type Description
text string

The copy that you would like the text to display

style object

The style parameters

Properties
Name Type Argument Default Description
font string | object

The font descriptor for the object, can be passed as a string of form
"24px FontName" or "FontName" or as an object with explicit name/size properties.

Properties
Name Type Argument Description
name string <optional>

The bitmap font id

size number <optional>

The size of the font in pixels, e.g. 24

align string <optional>
'left'

Alignment for multiline text ('left', 'center' or 'right'), does not affect
single line text

tint number <optional>
0xFFFFFF

The tint color

Source:

Extends

Members


alpha :Number

The opacity of the node.

Type:
Inherited From:
Source:

cacheAsBitmap :boolean

Set this to true if you want this display object to be cached as a bitmap.
This basically takes a snap shot of the display object as it is at that moment. It can provide a performance benefit for complex static displayObjects.
To remove simply set this property to 'false'

Type:
  • boolean
Inherited From:
Source:

<readonly> children :Array.<Node>

The list of children added to this node.

Type:
Inherited From:
Source:

dirty :boolean

The dirty state of this object.

Type:
  • boolean
Source:

filterArea :Rectangle

The area the filter is applied to. This is used as more of an optimisation
rather than figuring out the dimensions of the node each frame you can set this rectangle

Type:
Inherited From:
Source:

filters :Array.<AbstractFilter>

Sets the filters for this Node.

  • IMPORTANT: This is a WebGL only feature and will be ignored by the canvas renderer.
    To remove filters simply set this property to 'null'
Type:
Inherited From:
Source:

height :Number

The height of the Node, setting this will actually modify the scale to achieve the value set

Type:
Inherited From:
Source:

mask :Graphics|Sprite

Sets a mask for this Node. A mask is an object that limits the visibility of an object to the shape of the mask applied to it.
A regular mask must be a Graphics or a Sprite object. This allows for much faster masking in canvas as it utilises shape clipping.
To remove a mask, set this property to null.

Type:
Inherited From:
Source:
To Do:
  • For the moment, CanvasRenderer doesn't support Sprite as mask.

maxLineHeight :number

The max line height. This is useful when trying to use the total height of the Text, ie: when trying to vertically align.

Type:
  • number
Source:

maxWidth :number

The max width of this bitmap text in pixels. If the text provided is longer than the value provided, line breaks will be automatically inserted in the last whitespace.
Disable by setting value to 0

Type:
  • number
Source:

<readonly> parent :Node

The node that contains this one.

Type:
Inherited From:
Source:

pivot :Vector

The pivot point of the node that it rotates around

Type:
Inherited From:
Source:

position :Vector

The coordinate of the node relative to the local coordinates of the parent.

Type:
Inherited From:
Source:

renderable :Boolean

Can this node be rendered, if false the node will not be drawn but the updateTransform
methods will still be called.

Type:
  • Boolean
Inherited From:
Source:

rotation :Number

The rotation of the node in radians.

Type:
Inherited From:
Source:

scale :Vector

The scale factor of the node.

Type:
Inherited From:
Source:

skew :Vector

The skew factor for the node in radians.

Type:
Inherited From:
Source:

system :SystemGfx

Sets the gfx system this node will be rendered with

Type:
Inherited From:
Source:

<readonly> textHeight :number

The height of the overall text, different from fontSize,
which is defined in the style object

Type:
  • number
Source:

<readonly> textWidth :number

The width of the overall text, different from fontSize,
which is defined in the style object

Type:
  • number
Source:

visible :Boolean

The visibility of the node. If false the node will not be drawn, and
the updateTransform function will not be called.

Type:
  • Boolean
Inherited From:
Source:

width :Number

The width of the Node, setting this will actually modify the scale to achieve the value set

Type:
Inherited From:
Source:

<readonly> worldAlpha :Number

The multiplied alpha of the node

Type:
Inherited From:
Source:

<readonly> worldTransform :Matrix

Current transform of the node based on world (parent) factors

Type:
Inherited From:
Source:

<readonly> worldVisible :Boolean

Indicates if this node is globally visible.

Type:
  • Boolean
Inherited From:
Source:

x :Number

The position of this Node on the x axis relative to the local coordinates of the parent.

Type:
Inherited From:
Source:

y :Number

The position of this Node on the y axis relative to the local coordinates of the parent.

Type:
Inherited From:
Source:

Methods


addListener()

Inherited From:
Source:

emit(event, a1, a2, a3, a4, a5)

Emit an event to all registered event listeners.

Parameters:
Name Type Description
event string

The name of the event.

a1 *

First param

a2 *

Second param

a3 *

Third param

a4 *

Forth param

a5 *

Fifth param

Inherited From:
Source:
Returns:

Indication if we've emitted an event.

Type
boolean

getLocalBounds()

Validates text before calling parent's getLocalBounds

Source:
Returns:

The rectangular bounding area

Type
Rectangle

listeners(event, exists)

Return a list of assigned event listeners.

Parameters:
Name Type Description
event string

The events that should be listed.

exists boolean

We only need to know if there are listeners.

Inherited From:
Source:
Returns:

Listener list

Type
array | boolean

off()

Inherited From:
Source:

on(event, fn, context)

Register a new EventListener for the given event.

Parameters:
Name Type Description
event string

Name of the event.

fn functon

Callback function.

context Mixed

The context of the function.

Inherited From:
Source:
Returns:

Self for chaining

Type
EventEmitter

once(event, fn, context)

Add an EventListener that's only called once.

Parameters:
Name Type Description
event string

Name of the event.

fn function

Callback function.

context Mixed

The context of the function.

Inherited From:
Source:
Returns:

Self for chaining

Type
EventEmitter

removeAllListeners(event)

Remove all listeners or only the listeners for the specified event.

Parameters:
Name Type Description
event string

The event want to remove all listeners for.

Inherited From:
Source:
Returns:

Self for chaining

Type
EventEmitter

removeListener(event, fn, context, once)

Remove event listeners.

Parameters:
Name Type Description
event string

The event we want to remove.

fn function

The listener that we need to find.

context Mixed

Only remove listeners matching this context.

once boolean

Only remove once listeners.

Inherited From:
Source:
Returns:

Self for chaining

Type
EventEmitter

setTransform( [x] [, y] [, scaleX] [, scaleY] [, rotation] [, skewX] [, skewY] [, pivotX] [, pivotY])

Convenience function to set the postion, scale, skew and pivot at once.

Parameters:
Name Type Argument Default Description
x Number <optional>
0

The X position

y Number <optional>
0

The Y position

scaleX Number <optional>
1

The X scale value

scaleY Number <optional>
1

The Y scale value

rotation Number <optional>
0

The rotation

skewX Number <optional>
0

The X skew value

skewY Number <optional>
0

The Y skew value

pivotX Number <optional>
0

The X pivot value

pivotY Number <optional>
0

The Y pivot value

Inherited From:
Source:
Returns:

This for chaining.

Type
Node

toGlobal(position)

Calculates the global position of this node

Parameters:
Name Type Description
position Vector

The world origin to calculate from

Inherited From:
Source:
Returns:

A point representing the position of this node

Type
Vector

toLocal(position [, from] [, point])

Calculates the local position of this node relative to another point

Parameters:
Name Type Argument Description
position Vector

The world origin to calculate from

from Node <optional>

The Node to calculate the global position from

point Vector <optional>

A Point in which to store the value, optional (otherwise will create a new Point)

Inherited From:
Source:
Returns:

A point representing the position of this node

Type
Vector