Constructor
new GameText(text, attrs)
Constructor of Text drawable
Parameters:
Name | Type | Default | Description |
---|---|---|---|
text |
string | sample text | Displayed text |
attrs |
Object | Attribute object |
Properties:
Name | Type | Description |
---|---|---|
color |
string | Color of text. Can be CSS color. |
text |
string | Text to display. Can be only 1 line |
font |
string | Font (and size) of the text. Default "20px arial" |
maxWidth |
number | Shrink text width to this size |
- Source:
Extends
Methods
copy(newName) → {GameText}
Returns copy of current instance.
Parameters:
Name | Type | Description |
---|---|---|
newName |
string | Name of the newly created instance. Names have to be unique. |
- Overrides:
- Source:
Returns:
New instance of GameText with the same attributes.
- Type
- GameText
draw(ctx)
Transforms input context and calls draw function of passed drawable.
Parameters:
Name | Type | Description |
---|---|---|
ctx |
CanvasRenderingContext2D | Rendering context. |
- Overrides:
- Source:
drawFunction(ctx)
Called when drawing
Parameters:
Name | Type | Description |
---|---|---|
ctx |
CanvasRenderingContext2D | Rendering context on which the method draws |
- Overrides:
- Source:
getAttrs() → {Object}
Returns object of attributes of current instance.
- Overrides:
- Source:
Returns:
Attribute object.
- Type
- Object
isInside(mouse, tempContext) → {boolean}
Returns true when mouse is inside drawable.
Parameters:
Name | Type | Description |
---|---|---|
mouse |
Point | Mouse position on canvas. |
tempContext |
CanvasRenderingContext2D | Hidden rendering context to check pixel state. |
- Overrides:
- Source:
Returns:
True when mouse is inside drawable, false otherwise.
- Type
- boolean
measureText(ctx) → {TextMetrics}
Returns measures of the drawable
Parameters:
Name | Type | Description |
---|---|---|
ctx |
CanvasRenderingContext2D | Rendering context upon which the calculations are made |
- Source:
Returns:
text metrics
- Type
- TextMetrics