onCanvas()

Checks if the touch position is inside the canvas.

Syntax onCanvas()

Return Type Boolean

Description

Checks if the touch position is inside the canvas.

Return Value

Boolean. Returns true if the pointer is inside the canvas, and false otherwise.

Examples

Example 1

We create a core instance and a text object that will show if the finger is inside the canvas or not. A loop is set up, which will run 30 times per second and update the text with the current answer to the question.

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

var text = canvas.display.text({
	x: 177,
	y: 140,
	origin: { x: "center", y: "top" },
	align: "center",
	font: "bold 25px/1.5 sans-serif",
	text: "Is the finger inside\nthe canvas?\nNo",
	fill: "#000"
});

canvas.addChild(text);

canvas.setLoop(function () {
	text.text = "Is the finger inside\nthe canvas?\n" +
			(canvas.touch.onCanvas() ? "Yes" : "No");
}).start();
Output