me.event

an event system based on a micro publish/subscribe messaging framework

Members

static, constant CANVAS_ONRESIZE :String

Channel Constant for when the canvas is resized
(this usually follows a WINDOW_ONRESIZE event).
Data passed : {Number} canvas width
Data passed : {Number} canvas height

See:

static, constant DRAGEND :String

Channel Constant for dragend events on a Draggable entity
Data passed: {Object} the drag event
{Object} the Draggable entity

See:

static, constant DRAGSTART :String

Channel Constant for dragstart events on a Draggable entity
Data passed: {Object} the drag event
{Object} the Draggable entity

See:

static, constant GAME_INIT :String

Channel Constant for when the game manager is initialized
Data passed : none

See:

static, constant GAME_RESET :String

Channel Constant for when the game manager is resetted
Data passed : none

See:

static, constant GAMEPAD_CONNECTED :String

Channel Constant for when a gamepad is connected
Data passed : {Object} gamepad object

See:

static, constant GAMEPAD_DISCONNECTED :String

Channel Constant for when a gamepad is disconnected
Data passed : {Object} gamepad object

See:

static, constant GAMEPAD_UPDATE :String

Channel Constant for when gamepad button/axis state is updated
Data passed : {Number} index
Data passed : {String} type : "axes" or "buttons"
Data passed : {Number} button
Data passed : {Number} current.value
Data passed : {Boolean} current.pressed

See:

static, constant KEYDOWN :String

Channel Constant for pressing a binded key
Data passed : {String} user-defined action, {Number} keyCode, {Boolean} edge state
Edge-state is for detecting "locked" key bindings. When a locked key is pressed and held, the first event will have the third argument set true. Subsequent events will continue firing with the third argument set false.

See:
Example
me.input.bindKey(me.input.KEY.X, "jump", true); // Edge-triggered
me.input.bindKey(me.input.KEY.Z, "shoot"); // Level-triggered
me.event.subscribe(me.event.KEYDOWN, function (action, keyCode, edge) {
  // Checking bound keys
  if (action === "jump") {
      if (edge) {
          this.doJump();
      }

      // Make character fall slower when holding the jump key
      this.vel.y = this.body.gravity;
  }
});

static, constant KEYUP :String

Channel Constant for releasing a binded key
Data passed : {String} user-defined action, {Number} keyCode

See:
Example
me.event.subscribe(me.event.KEYUP, function (action, keyCode) {
  // Checking unbound keys
  if (keyCode == me.input.KEY.ESC) {
      if (me.state.isPaused()) {
          me.state.resume();
      }
      else {
          me.state.pause();
      }
  }
});

static, constant LEVEL_LOADED :String

Channel Constant for when a level is loaded
Data passed : {String} Level Name

See:

static, constant LOADER_COMPLETE :String

Channel Constant for when everything has loaded
Data passed : none

See:

static, constant LOADER_PROGRESS :String

Channel Constant for displaying a load progress indicator
Data passed : {Number} [0 .. 1], {Resource} resource object

See:

static, constant POINTERMOVE :String

Channel Constant for pointermove events on the screen area
Data passed : {me.Pointer} a Pointer object

See:

static, constant STATE_PAUSE :String

Channel Constant when the game is paused
Data passed : none

See:

static, constant STATE_RESTART :String

Channel Constant for when the game is restarted
Data passed : {Number} time in ms the game was stopped

See:

static, constant STATE_RESUME :String

Channel Constant for when the game is resumed
Data passed : {Number} time in ms the game was paused

See:

static, constant STATE_STOP :String

Channel Constant when the game is stopped
Data passed : none

See:

static, constant VIEWPORT_ONCHANGE :String

Channel Constant for when the viewport position is updated
Data passed : {me.Vector2d} viewport position vector

See:

static, constant VIEWPORT_ONRESIZE :String

Channel Constant for when the viewport is resized
(this usually follows a WINDOW_ONRESIZE event, when using the flex scaling mode is used and after the viewport was updated).
Data passed : {Number} viewport width
Data passed : {Number} viewport height

See:

static, constant WEBGL_ONCONTEXT_LOST :String

Channel Constant for when WebGL context is lost
Data passed : {me.WebGLRenderer} the current webgl renderer instance`

See:

static, constant WEBGL_ONCONTEXT_RESTORED :String

Channel Constant for when WebGL context is restored
Data passed : {me.WebGLRenderer} the current webgl renderer instance`

See:

static, constant WINDOW_ONORIENTATION_CHANGE :String

Channel Constant for when the device is rotated
Data passed : {Event} Event object

See:

static, constant WINDOW_ONRESIZE :String

Channel Constant for when the (browser) window is resized
Data passed : {Event} Event object

See:

static, constant WINDOW_ONSCROLL :String

Channel Constant for when the (browser) window is scrolled
Data passed : {Event} Event object

See:

Methods

static publish(channel, arguments)

Publish some data on a channel

Parameters:
Name Type Description
channel String

The channel to publish on

arguments Array

The data to publish

Example
Publish stuff on '/some/channel'.
Anything subscribed will be called with a function
signature like: function (a,b,c){ ... }

me.event.publish("/some/channel", ["a","b","c"]);

static subscribe(channel, callback) → {handle}

Register a callback on a named channel.

Parameters:
Name Type Description
channel String

The channel to subscribe to

callback function

The event handler, any time something is published on a subscribed channel, the callback will be called with the published array as ordered arguments

Returns:
handle -

A handle which can be used to unsubscribe this particular subscription

Example
me.event.subscribe("/some/channel", function (a, b, c){ doSomething(); });

static unsubscribe(handle, callbackopt)

Disconnect a subscribed function for a channel.

Parameters:
Name Type Attributes Description
handle Array | String

The return value from a subscribe call or the name of a channel as a String

callback function <optional>

The callback to be unsubscribed.

See:
Example
var handle = me.event.subscribe("/some/channel", function (){});
me.event.unsubscribe(handle);

// Or alternatively ...

var callback = function (){};
me.event.subscribe("/some/channel", callback);
me.event.unsubscribe("/some/channel", callback);