add()

Add an object to the scene.

Syntax add(object)

Return Type Scene

Description

Add an object to the scene. This will make the object to be drawn when the scene is loaded. If the scene is already loaded, the object will be drawn directly.

Arguments

object : displayObject
The display object that is going to be added to 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 first text object to the scene. We store the returned object in a variable. Then we add the second text object to the scene using the same add() method, but outside of the init function. Then finally we load our scene, and our text objects are 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);
});

menu.add(instructions);

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