remove()

Remove an object from the scene.

Syntax remove(object)

Return Type Scene

Description

Remove an object from the scene. This will remove the object from the canvas and it will not be drawn the next time the scene is loaded.

Arguments

object : displayObject
The display object that is going to be removed from the scene.

Return Value

Scene. Returns the scene instance itself.

Examples

Example 1

We create a core instance and two text objects, but we don't add them to the canvas. Then we create a new scene called menu. We pass a function as the init argument. Inside of that we add our text objects to the scene. We store the returned object in a variable. Then we remove the first text object from the scene using the remove() method. Then finally we load our scene, and only our second text object is added to canvas.

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

var startGame = canvas.display.text({
	x: 177,
	y: 170,
	origin: { x: "center", y: "top" },
	align: "center",
	font: "bold 30px sans-serif",
	text: "Start Game!",
	fill: "#000"
});

var instructions = startGame.clone({
	y: 240,
	text: "Instructions"
});

var menu = canvas.scenes.create("menu", function () {
	this.add(startGame);
	this.add(instructions);
});

menu.remove(startGame);

canvas.scenes.load("menu");
Output