clear()

Clear the canvas from all drawn objects.

Syntax clear(keepBackground)

Return Type Draw

Description

Clear the canvas from all drawn objects, with the ability to keep the background.

Arguments

keepBackground : Boolean
True if the background should be kept, and false if everything should be cleared.

Return Value

Draw. Returns the draw instance itself.

Examples

Example 1

First we create an instance of the core object. Then we create two rectangles and add them to the canvas. Finally we add event handlers that will clear the canvas when clicked. Left button keeps the background and the right button clears everything. Reload the output to try again.

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

var button_keep = canvas.display.rectangle({
		x: 30,
		y: 80,
		width: 132,
		height: 100,
		fill: "#000"
	}),
	button_clear = button_keep.clone({
		x: 192
	});

canvas.addChild(button_keep);
canvas.addChild(button_clear);

button_keep.bind("click tap", function () {
	canvas.draw.clear(); // true is the default
});

button_clear.bind("click tap", function () {
	canvas.draw.clear(false);
});
Output