Detecting clicks/taps on an object

Do something only when a specific object is clicked

You can set objects to listen for input events. When an object that is listening for onClick is clicked, its onClick function is executed.
App = function() { this.init = function() { // create a text sprite this.textSprite = new TextSprite('Click right here', '32px Arial', 'red', 'center'); // create a scene object this.textObject = new SceneObject(this.textSprite); // define what happens when the text object is clicked this.textObject.onClick = function() { // we access the sprite as, because this function is not a member of App, so using this.textSprite wouldn't work'Well done!'); }; // add the object to the scene wade.addSceneObject(this.textObject); // set our text object to listen for onClick events wade.addEventListener(this.textObject, 'onClick'); }; };
Your code was executed successfully!