new Object2D()
Base object class, implements all the object positioning and scalling features.
Stores all the base properties shared between all objects as the position, transformation properties, children etc.
Object2D should be used as a group to store all the other objects drawn.
- Source:
Members
beingDragged
Flag to indicate if the object is currently being dragged.
- Source:
children
List of children objects attached to the object.
- Source:
draggable
Indicates if its possible to drag the object around.
If true the onPointerDrag callback is used to update the state of the object.
- Source:
globalMatrix
Global transformation matrix multiplied by the parent matrix.
Used to transform the object before projecting into screen coordinates.
- Source:
ignoreViewport
Flag to indicate wheter this objet ignores the viewport transformation.
- Source:
inverseGlobalMatrix
Inverse of the global matrix.
Used to convert pointer input points into object coordinates.
- Source:
layer
Layer of this object, objects are sorted by layer value.
Lower layer value is draw first.
- Source:
level
Depth level in the object tree, objects with higher depth are drawn on top.
The layer value is considered first.
- Source:
masks
Masks being applied to this object.
Multiple masks can be used simultaneously.
- Source:
matrix
Local transformation matrix applied to the object.
- Source:
matrixNeedsUpdate
If true the matrix is updated before rendering the object.
- Source:
onAdd
Method called when the object its added to a parent.
- Source:
onButtonDown
Callback method called when the pointer button is pressed down (single time).
Receives (pointer, viewport) as arguments.
- Source:
onButtonPressed
Callback method called while the pointer button is pressed.
Receives (pointer, viewport) as arguments.
- Source:
onButtonUp
Callback method called when the pointer button is released (single time).
Receives (pointer, viewport) as arguments.
- Source:
onDoubleClick
Callback method called while the pointer button is double clicked.
Receives (pointer, viewport) as arguments.
- Source:
onPointerEnter
Callback method called when the pointer enters the object.
Receives (pointer, viewport) as arguments.
- Source:
onPointerLeave
Callback method called when the was inside of the object and leaves the object.
Receives (pointer, viewport) as arguments.
- Source:
onPointerOver
Callback method while the pointer is over (inside) of the object.
Receives (pointer, viewport) as arguments.
- Source:
onRemove
Method called when the object gets removed from its parent
- Source:
onUpdate
Callback method called every time before the object is draw into the canvas.
Can be used to run preparation code, move the object, etc.
- Source:
origin
Origin of the object used as point of rotation.
- Source:
parent
Parent object, the object position is affected by its parent position.
- Source:
pointerEvents
Indicates if this object uses pointer events.
Can be set false to skip the pointer interaction events.
- Source:
pointerInside
Flag indicating if the pointer is inside of the element.
Used to control object event.
- Source:
position
Position of the object.
- Source:
restoreContextState
Flag to indicate if the context of canvas should be restored after render.
- Source:
rotation
Rotation of the object relative to its center.
- Source:
saveContextState
Flag to indicate if the context of canvas should be saved before render.
- Source:
scale
Scale of the object.
- Source:
uuid
UUID of the object.
- Source:
visible
Indicates if the object is visible.
- Source:
Methods
add(object)
Attach a children to this object.
The object is set as children of this object and the transformations applied to this object are traversed to its children.
Parameters:
Name | Type | Description |
---|---|---|
object |
Object2D | Object to attach to this object. |
- Source:
draw(context, viewport, canvas)
Draw the object into the canvas.
Has to be implemented by underlying classes.
Parameters:
Name | Type | Description |
---|---|---|
context |
CanvasContext | Canvas 2d drawing context. |
viewport |
Viewport | Viewport applied to the canvas. |
canvas |
DOM | DOM canvas element where the content is being drawn. |
- Source:
getChildByUUID(uuid) → {Object2D}
Get a object from its children list by its UUID.
Parameters:
Name | Type | Description |
---|---|---|
uuid |
String | UUID of the object to get. |
- Source:
Returns:
The object that has the UUID specified, null if the object was not found.
- Type
- Object2D
isInside() → {boolean}
Check if a point is inside of the object.
Used to update the point events attached to the object.
- Source:
Returns:
True if the point is inside of the object.
- Type
- boolean
onPointerDrag(pointer, viewport, delta)
Callback method while the object is being dragged across the screen.
By default is adds the delta value to the object position (making it follow the mouse movement).
Delta is the movement of the pointer already translated into local object coordinates.
Receives (pointer, viewport, delta) as arguments.
Parameters:
Name | Type | Description |
---|---|---|
pointer |
Pointer | Pointer object that receives the user input. |
viewport |
Viewport | Viewport where the object is drawn. |
delta |
Vector2 | Pointer movement in world space. |
- Source:
remove(object)
Remove object from the children list.
Parameters:
Name | Type | Description |
---|---|---|
object |
Object2D | Object to be removed. |
- Source:
transform(context, viewport)
Apply the transform to the rendering context.
It is assumed that the viewport transform is pre-applied to the context.
Can also be used for pre rendering logic.
Parameters:
Name | Type | Description |
---|---|---|
context |
CanvasContext | Canvas 2d drawing context. |
viewport |
Viewport | Viewport applied to the canvas. |
- Source:
traverse(callback)
Traverse the object tree and run a function for all objects.
Parameters:
Name | Type | Description |
---|---|---|
callback |
function | Callback function that receives the object as parameter. |
- Source:
updateMatrix(context)
Update the transformation matrix of the object.
Parameters:
Name | Type | Description |
---|---|---|
context |
CanvasContext |
- Source: