clear()

Clear the canvas from all drawn objects.

Syntax clear(keepBackground)

Return Type Core

Description

Clear the canvas from all drawn objects, with the ability to keep the background. Shorthand method for the clear() method in the draw module.

Arguments

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

Return Value

Core. Returns the core 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 listeners 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.clear(); // true is the default
});

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