Constructor
new GameShape(type, attrs)
Constructor of Shape drawable
Parameters:
Name | Type | Default | Description |
---|---|---|---|
type |
TYPE | rectangle | Type of shape: rectangle, oval, polygon, line |
attrs |
Object | Attribute object |
Properties:
Name | Type | Description |
---|---|---|
type |
TYPE | Type of shape: rectangle, oval, polygon, line |
fill |
string | Fill of the shape. Can be CSS color or "random" |
stroke |
string | Stroke of the shape. Can be CSS color or "random" |
lineWidth |
number | Width of the line/outline |
rx |
number | Radius of oval on X axis |
ry |
number | Radius of oval on Y axis |
coords |
Array.<number> | Array of points in line/polygon in format [x1,y1,...,xn,yn] |
- Source:
Extends
Methods
addPoint(point)
Appends Point to the coords array
Parameters:
Name | Type | Description |
---|---|---|
point |
Point |
- Source:
copy(newName) → {GameShape}
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 GameShape with the same attributes.
- Type
- GameShape
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
parsePath(path) → {Array.<Number>}
Parses path in format "x y command number c n c n ..."
Parameters:
Name | Type | Description |
---|---|---|
path |
string |
- Source:
Returns:
- Type
- Array.<Number>
setLine(from, to)
Replaces coords array property with two points
Parameters:
Name | Type | Description |
---|---|---|
from |
Point | Start Point |
to |
Point | End Point |
- Source:
setPath(path)
Sets coords from path
Parameters:
Name | Type | Description |
---|---|---|
path |
string |
- Source: