Show:
Extends SimpleStream

Wrapper for DOM mouse events. Converts

 mousedown -> start
 mousemove -> update
 mouseup   -> end

MouseInput emits these events with the following payload data:

 value     - Displacement in pixels from mousedown
 delta     - Differential in pixels between successive mouse positions
 velocity  - Velocity of mouse movement in pixels per second
 cumulate  - Accumulated value over successive displacements
 event     - Original DOM event
 dt        - Time since last update

Constructor

Inputs.MouseInput

(
  • [options]
)

Parameters:

  • [options] Object optional

    Options

    • [scale=1] Number optional

      Scale the response to the mouse

    • [direction] Number optional

      Direction to project movement onto. Options found in MouseInput.DIRECTION.

    • [rails=false] Boolean optional

      If a direction is specified, movement in the orthogonal direction is suppressed

Example:

 var surface = new Surface({
             size : [100,100],
             properties : {background : 'red'}
         });
        
         var mouseInput = new MouseInput({
             direction : MouseInput.DIRECTION.X
         });
        
         mouseInput.subscribe(surface);
        
         mouseInput.on('start', function(payload){
             // fired on mouse down
             console.log('start', payload);
         });
        
         mouseInput.on('update', function(payload){
             // fired on mouse move
             console.log('update', payload);
         });
        
         mouseInput.on('end', function(payload){
             // fired on mouse up
             console.log('end', payload);
         });

Item Index

Properties

Properties

DIRECTION

Object static

Constrain the input along a specific axis.

Sub-properties: