Behaviors

Decide how objects should respond to events in their behavior functions

Behaviors are functions that determine how your objects behave (for example how they respond to events). You can assign your objects one or more behaviors. When an object receives an event, all its behaviors receive that same event too. Behaviors can access the parent objects via this.owner. This is useful if you want to separate and encapsulte the logic that controls the behavior of your objects (you could define each behavior in a separate javascript file for example), or if you like to use an entity/component architecture for your code.
// define a behavior function TestBehavior = function() { this.onAddToScene = function() { this.owner.moveTo(150, 150, 50); }; this.onClick = function() { this.owner.getSprite().setText('Good job'); }; }; App = function() { this.init = function() { // create a text object that uses our TestBehavior var textSprite = new TextSprite('Click me', '32px Arial', 'red', 'center'); var textObject = new SceneObject(textSprite, TestBehavior); // add the object to the scene and listen for handled events wade.addSceneObject(textObject, true); }; };
Your code was executed successfully!