1 /** 2 * @class buttonListener 3 * @description 4 * An object to listen to input. See {@link sandboxe.input.buttonListener.create} to instantiate 5 * and enable it. </br></br> 6 * 7 * buttonListener allows you to set up more detailed specific behavior as soon 8 * as an input even is recorded for a frame, allowing you to avoid the classic 9 * "query input every frame pattern". </br></br> 10 * 11 * Example: </br></br> 12 * @example 13 // creates the button listener and automatically links it 14 // to start listening for the button. In this case, the space key 15 listener = sandboxe.input.buttonListener.create(sandboxe.key_space); 16 17 // Sets the message for the press event 18 listener.onPress = function() { 19 sandboxe.console.info('Space was pressed!\n'); 20 } 21 22 // Sets the message for the hold event 23 listener.onHold = function() { 24 sandboxe.console.info('Space was held!\n'); 25 } 26 27 // Sets the message for the release event 28 listener.onRelease = function() { 29 sandboxe.console.info('Space was released!\n'); 30 } 31 32 33 34 35 * 36 */ 37 function buttonListener() { 38 39 /** 40 * The user function to call when the input is pressed / activated 41 * @type {Function} 42 */ 43 this.onPress = {}; 44 45 /** 46 * The user function to call when the input is held. It is called 47 * every frame that it is held until it is release. 48 * @type {Function} 49 */ 50 this.onHold = {}; 51 52 /** 53 * The user function to call when the input is released. 54 * @type {Function} 55 */ 56 this.onRelease = {}; 57 58 /** 59 * Removes the button listener from sandboxe. 60 */ 61 this.remove = function(){}; 62 63 64 65 return this; 66 }