# JSDoc: Class: Object2D

# Class: Object2D

## Object2D()

#### 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:
  - Object2D.js, line 16

### Members

#### beingDragged

Flag to indicate if the object is currently being dragged.

Source:
  - Object2D.js, line 142

#### children

List of children objects attached to the object.

Source:
  - Object2D.js, line 26

#### 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:
  - Object2D.js, line 108

#### globalMatrix

Global transformation matrix multiplied by the parent matrix. Used to transform the object before projecting into screen coordinates.

Source:
  - Object2D.js, line 82

#### ignoreViewport

Flag to indicate wheter this objet ignores the viewport transformation.

Source:
  - Object2D.js, line 120

#### inverseGlobalMatrix

Inverse of the global matrix. Used to convert pointer input points into object coordinates.

Source:
  - Object2D.js, line 89

#### layer

Layer of this object, objects are sorted by layer value. Lower layer value is draw first.

Source:
  - Object2D.js, line 70

#### level

Depth level in the object tree, objects with higher depth are drawn on top. The layer value is considered first.

Source:
  - Object2D.js, line 38

#### masks

Masks being applied to this object. Multiple masks can be used simultaneously.

Source:
  - Object2D.js, line 96

#### matrix

Local transformation matrix applied to the object.

Source:
  - Object2D.js, line 75

#### matrixNeedsUpdate

If true the matrix is updated before rendering the object.

Source:
  - Object2D.js, line 101

#### onAdd

Method called when the object its added to a parent.

Source:
  - Object2D.js, line 316

#### onButtonDown

Callback method called when the pointer button is pressed down (single time). Receives (pointer, viewport) as arguments.

Source:
  - Object2D.js, line 390

#### onButtonPressed

Callback method called while the pointer button is pressed. Receives (pointer, viewport) as arguments.

Source:
  - Object2D.js, line 370

#### onButtonUp

Callback method called when the pointer button is released (single time). Receives (pointer, viewport) as arguments.

Source:
  - Object2D.js, line 400

#### onDoubleClick

Callback method called while the pointer button is double clicked. Receives (pointer, viewport) as arguments.

Source:
  - Object2D.js, line 380

#### onPointerEnter

Callback method called when the pointer enters the object. Receives (pointer, viewport) as arguments.

Source:
  - Object2D.js, line 340

#### onPointerLeave

Callback method called when the was inside of the object and leaves the object. Receives (pointer, viewport) as arguments.

Source:
  - Object2D.js, line 350

#### onPointerOver

Callback method while the pointer is over (inside) of the object. Receives (pointer, viewport) as arguments.

Source:
  - Object2D.js, line 360

#### onRemove

Method called when the object gets removed from its parent

Source:
  - Object2D.js, line 323

#### 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:
  - Object2D.js, line 330

#### origin

Origin of the object used as point of rotation.

Source:
  - Object2D.js, line 48

#### parent

Parent object, the object position is affected by its parent position.

Source:
  - Object2D.js, line 31

#### pointerEvents

Indicates if this object uses pointer events. Can be set false to skip the pointer interaction events.

Source:
  - Object2D.js, line 115

#### pointerInside

Flag indicating if the pointer is inside of the element. Used to control object event.

Source:
  - Object2D.js, line 137

#### position

Position of the object.

Source:
  - Object2D.js, line 43

#### restoreContextState

Flag to indicate if the context of canvas should be restored after render.

Source:
  - Object2D.js, line 130

#### rotation

Rotation of the object relative to its center.

Source:
  - Object2D.js, line 58

#### saveContextState

Flag to indicate if the context of canvas should be saved before render.

Source:
  - Object2D.js, line 125

#### scale

Scale of the object.

Source:
  - Object2D.js, line 53

#### uuid

UUID of the object.

Source:
  - Object2D.js, line 21

#### visible

Indicates if the object is visible.

Source:
  - Object2D.js, line 63

### 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:
  - Object2D.js, line 190

#### 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:
  - Object2D.js, line 291

#### 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:
  - Object2D.js, line 168

##### 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:
  - Object2D.js, line 240

##### 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:
  - Object2D.js, line 306

#### remove(object)

Remove object from the children list.

##### Parameters:

Name | Type | Description
--- | --- | ---
`object` | Object2D | Object to be removed.

Source:
  - Object2D.js, line 211

#### 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:
  - Object2D.js, line 277

#### 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:
  - Object2D.js, line 150

#### updateMatrix(context)

Update the transformation matrix of the object.

##### Parameters:

Name | Type | Description
--- | --- | ---
`context` | CanvasContext |

Source:
  - Object2D.js, line 250