Two.Shape

Extends: Two.Element

The foundational transformation object for the Two.js scenegraph.

fromObject

Returns: Two.Shape

ArgumentDescription
objObject notation of a Two.Shape to create a new instance

Create a new Two.Shape from an object notation of a Two.Shape.

nota-bene

Works in conjunction with Two.Shape.toObject

renderer

Object access to store relevant renderer specific variables. Warning: manipulating this object can create unintended consequences.

nota-bene

With the Two.SVGRenderer you can access the underlying SVG element created via shape.renderer.elem.

matrix

The transformation matrix of the shape.

nota-bene

Two.Shape.position, Two.Shape.rotation, Two.Shape.scale, Two.Shape.skewX, and Two.Shape.skewY apply their values to the matrix when changed. The matrix is what is sent to the renderer to be drawn.

worldMatrix

The transformation matrix of the shape in the scene.

position

The x and y value for where the shape is placed relative to its parent.

rotation

The value in Number for how much the shape is rotated relative to its parent.

scale

The value for how much the shape is scaled relative to its parent.

nota-bene

This value can be replaced with a Two.Vector to do non-uniform scaling. e.g: shape.scale = new Two.Vector(2, 1);

skewX

The value in Number for how much the shape is skewed relative to its parent.

Skew the shape by an angle in the x axis direction.

skewY

The value in Number for how much the shape is skewed relative to its parent.

Skew the shape by an angle in the y axis direction.

addTo

ArgumentDescription
groupThe parent the shape adds itself to.

Convenience method to add itself to the scenegraph.

remove

Remove self from the scene / parent.

contains

Returns: Boolean

ArgumentDescription
xx coordinate to hit test against
yy coordinate to hit test against
optionsOptional options object
options.ignoreVisibilityIf true, hit test against shape.visible = false shapes
options.tolerancePadding to hit test against in pixels

Check to see if coordinates are within a Two.Shape's bounding rectangle

nota-bene

Expects world-space coordinates – the same pixel-space you get from the renderer (e.g., mouse clientX/clientY adjusted for the canvas’s offset and pixel ratio).

copy

ArgumentDescription
shape

Copy the properties of one Two.Shape onto another.

clone

Returns: Two.Shape

ArgumentDescription
parentOptional argument to automatically add the shape to a scenegraph.

Create a new Two.Shape with the same values as the current shape.

toObject

Create a JSON compatible object that represents information of the shape.

nota-bene

Works in conjunction with Two.Shape.fromObject

dispose

Release the shape's bound objects by unbinding relevant events.