setLoop()

Set a loop function.

Syntax setLoop(function)

Return Type Timeline

Description

Set a loop function. This doesn't start the timeline, it just lets the timeline module know what function it should call when the timeline is running. The function gets passed the native canvas context as its first argument, to enable drawing with the native canvas API. This method exists on the core instance.

Arguments

function : Function
A function that will be run the set number of times per second when the timeline is running.

Return Value

Timeline. Returns the timeline object.

Examples

Example 1

We create a new core instance and a rectangle that we add to the canvas. Then we set the loop function which will increase the rotation of the rectangle by 1 degree. The setLoop() method returns the timeline object, which has a start() method that we call to start the loop.

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

var rectangle = canvas.display.rectangle({
	x: 177,
	y: 170,
	origin: { x: "center", y: "center" },
	width: 200,
	height: 100,
	fill: "#000"
});

canvas.addChild(rectangle);

canvas.setLoop(function () {
	rectangle.rotation++;
}).start();
Output