Mouse

View source

Provides the current mouse-pointer motion and wheel state as a world resource.

The pointer position is local to the input target. Movement and wheel values describe the mouse input received during the current update.

If there is no mouse input during an update, the pointer position stays unchanged and the movement and wheel values are zero. Use MouseButtons for mouse-button state.

Examples

// Read the current mouse state:
function readMouse(world) {
  const mouse = world.getResource(Mouse)

  if (mouse.moved()) {
    console.log(mouse.position.x, mouse.position.y, mouse.delta.x, mouse.delta.y)
  }
}

Constructor


constructor()

Properties


lastPosition: Vector2

View source

Pointer position from the previous update.

This can be used with Mouse#position to compare the pointer’s position across updates.

Default: ...

position: Vector2

View source

Current pointer position in the input target’s local coordinates.

It remains unchanged when the pointer does not move.

Default: ...

delta: Vector2

View source

Mouse movement during the current update.

It is Vector2.Zero when the mouse does not move.

Default: ...

wheelDelta: Vector3

View source

Mouse-wheel movement during the current update.

The value is Vector3.Zero when the wheel does not move and includes horizontal, vertical, and depth-axis scroll movement.

Default: ...

Methods


moved(): boolean

View source

Reports whether the current update contains non-zero pointer movement.

This is exactly !this.delta.equals(Vector2.Zero), so either non-zero component makes the result true; equal zero components make it false.