event
namespace event
an event system based on nodeJS EventEmitter interface
Summary
Properties from event
Public Properties
BLUR: string = "me.blur"
string
event generated when the main browser or window is losing focus
CANVAS_ONRESIZE: string = "canvas.onresize"
string
Event for when the canvas is resized
(this usually follows a WINDOW_ONRESIZE event).
Data passed : {number} canvas width
Data passed : {number} canvas height
DOM_READY: string = "dom_ready"
string
event when the DOM is Ready is booting
DRAGEND: string = "me.game.dragend"
string
Event for dragend events on a Draggable entity
Data passed:
{object} the drag event
{object} the Draggable entity
DRAGSTART: string = "me.game.dragstart"
string
Event for dragstart events on a Draggable entity
Data passed:
{object} the drag event
{object} the Draggable entity
FOCUS: string = "me.focus"
string
event generated when the main browser or window is gaining back focus
GAME_AFTER_DRAW: string = "me.game.afterDraw"
string
Event for the start of the draw loop Data passed : {number} time the current time stamp
GAME_AFTER_UPDATE: string = "me.game.afterUpdate"
string
event for the end of the update loop Data passed : {number} time the current time stamp
GAME_BEFORE_DRAW: string = "me.game.beforeDraw"
string
Event for the end of the draw loop Data passed : {number} time the current time stamp
GAME_BEFORE_UPDATE: string = "me.game.beforeUpdate"
string
event for when the engine is about to start a new game loop Data passed : {number} time the current time stamp
GAME_INIT: string = "me.game.onInit"
string
event for when the game manager is initialized
Data passed : none
GAME_RESET: string = "me.game.onReset"
string
event for when the game manager is resetted
Data passed : none
GAME_UPDATE: string = "me.game.onUpdate"
string
Event for when the game is updated (will be impacted by frame skip, frame interpolation and pause/resume state)
Data passed : {number} time the current time stamp
GAMEPAD_CONNECTED: string = "gamepad.connected"
string
Event for when a gamepad is connected
Data passed : {object} gamepad object
GAMEPAD_DISCONNECTED: string = "gamepad.disconnected"
string
Event for when a gamepad is disconnected
Data passed : {object} gamepad object
GAMEPAD_UPDATE: string = "gamepad.update"
string
Event 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
KEYDOWN: string = "me.input.keydown"
string
Event 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.
me.input.bindKey(me.input.KEY.X, "jump", true); // Edge-triggered
me.input.bindKey(me.input.KEY.Z, "shoot"); // Level-triggered
me.event.on(me.event.KEYDOWN, (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;
}
});
KEYUP: string = "me.input.keyup"
string
Event for releasing a binded key
Data passed : {string} user-defined action, {number} keyCode
me.event.on(me.event.KEYUP, (action, keyCode) => {
// Checking unbound keys
if (keyCode == me.input.KEY.ESC) {
if (me.state.isPaused()) {
me.state.resume();
}
else {
me.state.pause();
}
}
});
LEVEL_LOADED: string = "me.game.onLevelLoaded"
string
Event for when a level is loaded
Data passed : {string} Level Name
LOADER_COMPLETE: string = "me.loader.onload"
string
Event for when everything has loaded
Data passed : none
LOADER_ERROR: string = "me.loader.onError"
string
Event for when an error occur during preloading
Data passed : {Resource} resource object
LOADER_PROGRESS: string = "me.loader.onProgress"
string
Event for displaying a load progress indicator
Data passed : {number} [0 .. 1], {Resource} resource object
ONCONTEXT_RESTORED: string = "renderer.contextrestored"
string
Event for when the current context is restored
Data passed : {me.Renderer} the current renderer instance`
POINTERLOCKCHANGE: string = "me.event.pointerlockChange"
string
Event for onPointerLockChange event
Data passed : {boolean} pointer lock status (true/false)
POINTERMOVE: string = "me.event.pointermove"
string
Event for pointermove events on the screen area
Data passed : {me.Pointer} a Pointer object
STAGE_RESET: string = "me.stage.onReset"
string
event for when a stage is resetted
STATE_CHANGE: string = "me.state.onChange"
string
event for when the changing to a different stage
STATE_PAUSE: string = "me.state.onPause"
string
event when the game is paused
Data passed : none
STATE_RESTART: string = "me.state.onRestart"
string
event for when the game is restarted
Data passed : {number} time in ms the game was stopped
STATE_RESUME: string = "me.state.onResume"
string
event for when the game is resumed
Data passed : {number} time in ms the game was paused
STATE_STOP: string = "me.state.onStop"
string
event when the game is stopped
Data passed : none
TICK: string = "me.tick"
string
event generated when the system update the engine and the renderer by one step
VIDEO_INIT: string = "me.video.onInit"
string
event for when the video is initialized
Data passed : {Renderer} the renderer instance created
VIEWPORT_ONCHANGE: string = "viewport.onchange"
string
Event for when the viewport position is updated
Data passed : {me.Vector2d} viewport position vector
VIEWPORT_ONRESIZE: string = "viewport.onresize"
string
Event 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
Data passed : {Camera2d} a reference to the camera viewport being resized
WEBGL_ONCONTEXT_LOST: string = "renderer.contextlost"
string
Event for when the current context is lost
Data passed : {me.Renderer} the current renderer instance
WINDOW_ONORIENTATION_CHANGE: string = "globalThis.orientationchange"
string
Event for when the device is rotated
Data passed : {Event} Event object
WINDOW_ONRESIZE: string = "globalThis.onresize"
string
Event for when the (browser) window is resized
Data passed : {Event} Event object
WINDOW_ONSCROLL: string = "globalThis.onscroll"
string
Event for when the (browser) window is scrolled
Data passed : {Event} Event object
WORLD_STEP: string = "me.world.step"
string
Event for when the physic world is updated Data passed : {number} time the current time stamp
Public Methods
emit(eventName: string | symbol, args: unknown) → {boolean}
calls each of the listeners registered for a given event.
me.event.emit("event-name", a, b, c);
Name | Type | Attributes | Description |
---|---|---|---|
eventName | string | symbol |
The event name. |
|
args | unknown |
<optional> |
arguments to be passed to all listeners |
Type | Description |
---|---|
boolean |
true if the event had listeners, false otherwise. |
off(eventName: string | symbol, listener: Function) → {EventEmitter}
remove the given listener for a given event.
me.event.off("event-name", myFunction);
Name | Type | Description |
---|---|---|
eventName | string | symbol |
The event name. |
listener | Function |
The listener function. |
Type | Description |
---|---|
EventEmitter |
|
on(eventName: string | symbol, listener: Function, context: unknown) → {EventEmitter}
Add a listener for a given event.
me.event.on("event-name", myFunction, this);
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
eventName | string | symbol |
The event name. |
||
listener | Function |
The listener function. |
||
context | unknown |
<optional> |
this |
The context to invoke the listener with. |
Type | Description |
---|---|
EventEmitter |
|
once(eventName: string | symbol, listener: Function, context: unknown) → {EventEmitter}
Add a one-time listener for a given event.
me.event.once("event-name", myFunction, this);
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
eventName | string | symbol |
The event name. |
||
listener | Function |
The listener function. |
||
context | unknown |
<optional> |
this |
The context to invoke the listener with. |
Type | Description |
---|---|
EventEmitter |
|