Class: Pointer

controls~Pointer()

Unified mouse and touch input.

Extends

Members

engine :module:core~Engine

A reference to the main engine.
Type:
Inherited From:
Source:

isDown :boolean

Wether or not the pointer is currently down.
Type:
  • boolean
Source:

listeners :object

A dictionary of the event callbacks attached to this object.
Type:
  • object
Inherited From:
Source:

name :string

The name you gave this instance of the ScenePlugin in the game config. If you gave the plugin the name `whiskymixer`, it will become available in the scene as property like in `this.whiskymixer`.
Type:
  • string
Inherited From:
Source:

scene :module:core~Scene

A reference to the scene where this plugin is active.
Type:
Inherited From:
Source:

Methods

emit(type, eopt)

Emits the event of a certain type and executes all callbacks.
Parameters:
Name Type Attributes Description
type string The name of the event it emits.
e object <optional>
An optional object that will be passed to the callbacks first argument.
Inherited From:
Source:

emitPointerEvent(e)

Calculates the events positions within the game, based on the native mouse or touch position and then emits the event.
Parameters:
Name Type Description
e object An object containing the name of the event to emit and position data of the native event.
Properties
Name Type Description
name object The name of the event to emit.
clientX number The native events x position relative to the browser window.
clientY number The native events y position relative to the browser window.
Source:

init()

Adds the necessary touch and mouse event listeners.
Overrides:
Source:

off(typeopt, callbackopt)

Removes listeners from this object.
Parameters:
Name Type Attributes Description
type string <optional>
The name of the event to remove callback(s) for. If left empty, it will remove every single callback from this object.
callback function <optional>
The callback to remove. If left empty, it will remove all callbacks for the given type or when the type is empty every single callback on this object.
Inherited From:
Source:

on(type, callback)

Continually listen on this object for an event.
Parameters:
Name Type Description
type string The name of the event.
callback function The function to execute each time the event is emitted.
Inherited From:
Source:

once(type, callback)

Listen on this object for an event, but execute the callback only once.
Parameters:
Name Type Description
type string The name of the event.
callback function The function to execute once.
Inherited From:
Source:

onMouseDown(e)

Called internally when a the mouse goes down.
Parameters:
Name Type Description
e object The native javascript event object.
Source:

onMouseMove(e)

Called internally when a the mouse moves.
Parameters:
Name Type Description
e object The native javascript event object.
Source:

onMouseUp(e)

Called internally when the mouse goes up.
Parameters:
Name Type Description
e object The native javascript event object.
Source:

onTouchEnd(e)

Called internally when the finger goes up.
Parameters:
Name Type Description
e object The native javascript event object.
Source:

onTouchMove(e)

Called internally when a the finger moves.
Parameters:
Name Type Description
e object The native javascript event object.
Source:

onTouchStart(e)

Called internally when a the finger goes down.
Parameters:
Name Type Description
e object The native javascript event object.
Source:

(abstract) postRender(context, time, delta)

Called on each frame if the scene is active. After all children are rendered. No need to call `super.postRender(context, time, delta)`
Parameters:
Name Type Description
context CanvasRenderingContext2D The canvas render context.
time number The total time (in milliesconds) since the start of the game.
delta number The time elapsed (in milliseconds) since the last frame.
Inherited From:
Source:

shutdown()

Removes all mouse and touch event listeners.
Overrides:
Source:

(abstract) update(time, delta)

Called on each frame if the scene is active. Before all children are rendered. No need to call `super.update(time, delta)`
Parameters:
Name Type Description
time number The total time (in milliesconds) since the start of the game.
delta number The time elapsed (in milliseconds) since the last frame.
Inherited From:
Source:

Events

pointerdown

Pointer down event.
Type:
  • object
Properties:
Name Type Description
viewportX number The x position relative to the top left of the scene's viewport.
viewportY number The y position relative to the top left of the scene's viewport.
worldX number The x position relative to the scene's origin.
worldY number The y position relative to the scene's origin.
Source:

pointermove

Pointer move event. On mobile this event only fires when the pointer is down. This is not the case on desktop. But you can check for the isDown property
Type:
  • object
Properties:
Name Type Description
viewportX number The x position relative to the top left of the scene's viewport.
viewportY number The y position relative to the top left of the scene's viewport.
worldX number The x position relative to the scene's origin.
worldY number The y position relative to the scene's origin.
Source:

pointerup

Pointer up event.
Type:
  • object
Properties:
Name Type Description
viewportX number The x position relative to the top left of the scene's viewport.
viewportY number The y position relative to the top left of the scene's viewport.
worldX number The x position relative to the scene's origin.
worldY number The y position relative to the scene's origin.
Source: