clone()

Clone a display object.

Syntax clone([settings])

Return Type displayObject

Description

Clone a display object and return a new instance with the old object's properties. Accepts an optional argument for setting properties for the new object. Since version 2.0.0, all children of the object will also be cloned and put as children of the new object.

Arguments

settings : Object
An object of properties that will be set on the new instance.

Return Value

displayObject. Returns the new display object.

Examples

Example 1

We create a new core instance and a rectangle. Then we create a clone of the rectangle and set the y value for the new instance, so they don't have the same position. Finally we add them both to the canvas.

View Example
Code
var canvas = oCanvas.create({
	canvas: "#canvas",
	background: "#ccc"
});

var rectangle_1 = canvas.display.rectangle({
	x: 77,
	y: 70,
	width: 200,
	height: 100,
	fill: "#000"
});

var rectangle_2 = rectangle_1.clone({
	y: 190
});

canvas.addChild(rectangle_1);
canvas.addChild(rectangle_2);
Output