Text.js
Text ⇐ Impacto.GameObjects.GameObject2D
This class will draw a text on the canvas.
Kind: global class
Extends: Impacto.GameObjects.GameObject2D
Constructors:
- Text ⇐
Impacto.GameObjects.GameObject2D
- new Text(x, y, Text, [fillColor], [strokeColor])
- .width ⇒
number
- .height ⇒
number
- .x
- .y
- .x ⇒
number
- .y ⇒
number
- .getTop() ⇒
number
- .getBottom() ⇒
number
- .getLeft() ⇒
number
- .getRight() ⇒
number
- .getCenterX() ⇒
number
- .getCenterY() ⇒
number
- .getRealTop() ⇒
number
- .getRealBottom() ⇒
number
- .getRealLeft() ⇒
number
- .getRealRight() ⇒
number
- .getRealCenterX() ⇒
number
- .getRealCenterY() ⇒
number
- .getWords() ⇒
Array.<string>
- .getWordsNumber() ⇒
number
- .getCharacters() ⇒
Array.<string>
- .getCharactersNumber() ⇒
number
- .setText(text) ⇒
Text
- .setFontSize(size) ⇒
Text
- .setFontFamily(family) ⇒
Text
- .setFontStyle(style) ⇒
Text
- .setFontVariant(variant) ⇒
Text
- .setFontWeight(weight) ⇒
Text
- .setFont(font) ⇒
Text
- .setAlignVertical(align) ⇒
Text
- .setAlignHorizontal(align) ⇒
Text
- .setDirection(direction) ⇒
Text
new Text(x, y, Text, [fillColor], [strokeColor])
Param | Type | Default | Description |
---|---|---|---|
x | number | The horizontal position of this Text in the world. | |
y | number | The vertical position of this Text in the world. | |
Text | number | The text will be drawn on the canvas. | |
[fillColor] | number | string | 0xffffff | The color the Text will be filled with, i.e. 0xff0000 for red. |
[strokeColor] | number | string | 0x000000 | The color of the border of the Text, i.e. 0x00ff00 for green. |
Example
const myText = new Impacto.GameObjects.Text(400, 300, "Hello World", "#ff0000", 0x00ff00);
Text.width ⇒ number
Returns the width of the text.
Kind: static property of Text
Returns: number
-
The width of the text.
Text.height ⇒ number
Returns the height of the text.
Kind: static property of Text
Returns: number
-
The height of the text.
Text.x
Sets the horizontal position of the text.
Kind: static property of Text
Param | Type | Description |
---|---|---|
align | string | The horizontal position of the text. |
Text.y
Sets the vertical position of the text.
Kind: static property of Text
Param | Type | Description |
---|---|---|
align | string | The vertical position of the text. |
Text.x ⇒ number
Returns the horizontal position of the text.
Kind: static property of Text
Returns: number
-
The horizontal position of the text.
Text.y ⇒ number
Returns the vertical position of the text.
Kind: static property of Text
Returns: number
-
The vertical position of the text.
Text.getTop() ⇒ number
Returns the top side position of the text.
Kind: static method of Text
Returns: number
-
The top side position of the text.
Example
new Impacto.GameObjects.Text(400, 300, "Hello World").getTop(); // 300
Text.getBottom() ⇒ number
Returns the bottom side position of the text.
Kind: static method of Text
Returns: number
-
The bottom side position of the text.
Example
new Impacto.GameObjects.Text(400, 300, "Hello World").getBottom(); // 300
Text.getLeft() ⇒ number
Returns the left side position of the text.
Kind: static method of Text
Returns: number
-
The left side position of the text.
Example
new Impacto.GameObjects.Text(400, 300, "Hello World").getLeft(); // 400
Text.getRight() ⇒ number
Returns the right side position of the text.
Kind: static method of Text
Returns: number
-
The right side position of the text.
Example
new Impacto.GameObjects.Text(400, 300, "Hello World").getRight(); // 400
Text.getCenterX() ⇒ number
Returns the horizontal center position of the text.
Kind: static method of Text
Returns: number
-
The horizontal center position of the text.
Example
new Impacto.GameObjects.Text(400, 300, "Hello World").getCenterX(); // 400
Text.getCenterY() ⇒ number
Returns the vertical center position of the text.
Kind: static method of Text
Returns: number
-
The vertical center position of the text.
Example
new Impacto.GameObjects.Text(400, 300, "Hello World").getCenterY(); // 300
Text.getRealTop() ⇒ number
Returns the real top side position of the text. (The position of the text without the offset)
Kind: static method of Text
Returns: number
-
The real top side position of the text.
Example
new Impacto.GameObjects.Text(400, 300, "Hello World").getRealTop(); // 300
Text.getRealBottom() ⇒ number
Returns the real bottom side position of the text. (The position of the text without the offset)
Kind: static method of Text
Returns: number
-
The real bottom side position of the text.
Example
new Impacto.GameObjects.Text(400, 300, "Hello World").getRealBottom(); // 300
Text.getRealLeft() ⇒ number
Returns the real left side position of the text. (The position of the text without the offset)
Kind: static method of Text
Returns: number
-
The real left side position of the text.
Example
new Impacto.GameObjects.Text(400, 300, "Hello World").getRealLeft(); // 400
Text.getRealRight() ⇒ number
Returns the real right side position of the text. (The position of the text without the offset)
Kind: static method of Text
Returns: number
-
The real right side position of the text.
Example
new Impacto.GameObjects.Text(400, 300, "Hello World").getRealRight(); // 400
Text.getRealCenterX() ⇒ number
Returns the real horizontal center position of the text. (The position of the text without the offset)
Kind: static method of Text
Returns: number
-
The real horizontal center position of the text.
Example
new Impacto.GameObjects.Text(400, 300, "Hello World").getRealCenterX(); // 400
Text.getRealCenterY() ⇒ number
Returns the real vertical center position of the text. (The position of the text without the offset)
Kind: static method of Text
Returns: number
-
The real vertical center position of the text.
Example
new Impacto.GameObjects.Text(400, 300, "Hello World").getRealCenterY(); // 300
Text.getWords() ⇒ Array.<string>
Returns all words of the text.
Kind: static method of Text
Returns: Array.<string>
-
All words of the text.
Example
new Impacto.GameObjects.Text(400, 300, "Hello World").getWords(); // ["Hello", "World"]
Text.getWordsNumber() ⇒ number
Returns the number of words of the text.
Kind: static method of Text
Returns: number
-
The number of words of the text.
Example
new Impacto.GameObjects.Text(400, 300, "Hello World").getWordsCount(); // 2
Text.getCharacters() ⇒ Array.<string>
Returns all characters of the text.
Kind: static method of Text
Returns: Array.<string>
-
All characters of the text.
Example
new Impacto.GameObjects.Text(400, 300, "Hello World").getCharacters(); // ["H", "e", "l", "l", "o", " ", "W", "o", "r", "l", "d"]
Text.getCharactersNumber() ⇒ number
Returns the number of characters of the text.
Kind: static method of Text
Returns: number
-
The number of characters of the text.
Example
new Impacto.GameObjects.Text(400, 300, "Hello World").getCharactersCount(); // 11
Text.setText(text) ⇒ Text
Change the display text.
Kind: static method of Text
Returns: Text
-
The text object.
Param | Type | Description |
---|---|---|
text | string | The new text. |
Example
new Impacto.GameObjects.Text(400, 300, "Hello World").setText("MyText");
Text.setFontSize(size) ⇒ Text
Change the font size.
Kind: static method of Text
Returns: Text
-
The text object.
Param | Type | Description |
---|---|---|
size | number | The new font size. |
Example
new Impacto.GameObjects.Text(400, 300, "Hello World").setFontSize(20);
Text.setFontFamily(family) ⇒ Text
Change the font family.
Kind: static method of Text
Returns: Text
-
The text object.
Param | Type | Description |
---|---|---|
family | string | The new font family. |
Example
new Impacto.GameObjects.Text(400, 300, "Hello World").setFontFamily("Arial");
Text.setFontStyle(style) ⇒ Text
Change the font style.
Kind: static method of Text
Returns: Text
-
The text object.
Param | Type | Description |
---|---|---|
style | string | The new font style. |
Example
new Impacto.GameObjects.Text(400, 300, "Hello World").setFontStyle("italic");
Text.setFontVariant(variant) ⇒ Text
Change the font variant.
Kind: static method of Text
Returns: Text
-
The text object.
Param | Type | Description |
---|---|---|
variant | string | The new font variant. |
Example
new Impacto.GameObjects.Text(400, 300, "Hello World").setFontVariant("small-caps");
Text.setFontWeight(weight) ⇒ Text
Change the font weight.
Kind: static method of Text
Returns: Text
-
The text object.
Param | Type | Description |
---|---|---|
weight | string | The new font weight. |
Example
new Impacto.GameObjects.Text(400, 300, "Hello World").setFontWeight("bold");
Text.setFont(font) ⇒ Text
Change the font.
Kind: static method of Text
Returns: Text
-
The text object.
Param | Type | Description |
---|---|---|
font | object | The new properties of the font. |
Example
new Impacto.GameObjects.Text(400, 300, "Hello World").setFont({
size: 20,
family: "Arial",
style: "italic",
variant: "small-caps",
weight: "bold"
});
Text.setAlignVertical(align) ⇒ Text
Change the vertical text alignment.
Kind: static method of Text
Returns: Text
-
The text object.
Param | Type | Description |
---|---|---|
align | string | The new text alignment. |
Example
new Impacto.GameObjects.Text(400, 300, "Hello World").setVerticalAlignment("top");
Text.setAlignHorizontal(align) ⇒ Text
Change the horizontal text alignment.
Kind: static method of Text
Returns: Text
-
The text object.
Param | Type | Description |
---|---|---|
align | string | The new text alignment. |
Example
new Impacto.GameObjects.Text(400, 300, "Hello World").setHorizontalAlignment("left");
Text.setDirection(direction) ⇒ Text
Change the direction of the text.
Kind: static method of Text
Returns: Text
-
The text object.
Param | Type | Description |
---|---|---|
direction | string | The new text direction. |
Example
new Impacto.GameObjects.Text(400, 300, "Hello World").setDirection("rtl");