create()

Create a new scene.

Syntax create(name, init)

Return Type Scene

Description

Create a new scene. Objects that are added in the init method will be added to canvas when the scene is loaded.

Arguments

name : String
The name of the scene. Will be used when loading the scene.
init : Function
A function that adds objects to the scene. this inside of the function refers to the scene instance, so to add objects use this.add(object). This function will be executed directly when the create() method executes. To add children after this stage, use the object that create() returns.

Return Value

Scene. Returns the newly created scene instance.

Examples

Example 1

We create a core instance and a text object, but we don't add it 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 object to the scene. Then finally we load our scene, and our 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"
});

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

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