like2d
    Preparing search index...

    Interface Mouse

    LIKE's mouse wrapper.

    Mouse coordinates are scaled for convenience. For example call:

    like.canvas.setMode([240, 160])
    

    and your game will now be 240x160 pixels.

    Your mouse coords will stay within the rectangle [0, 0] and [240, 160].

    If you intend to allow scrolling on your page while the mouse is above the game, use:

    like.mouse.setMode({ lock: false, scrollBlock: false })
    

    Some games benefit from capture aka pointer lock. Call

    like.mouse.setMode({ lock: true, speed: 1 })
    

    to use capture, and now the mouse is locked to the game.

    When you enter capture, the mouse pos becomes virtual, bounded to canvas edges, plus controlled via the speed setting and teleport-able via setCapturedPos.

    When you exit capture, the mouse will be in the same spot the capture was started in.

    Note that your mode settings from non-capture mode are preserved in capture mode and vice-versa.

    interface Mouse {
        setRelativeMode?: undefined;
        getMode(): MouseMode;
        getPosition(): Vector2;
        getPressedButtons(): Set<MouseButton>;
        isCursorVisible(): boolean;
        isDown(button: MouseButton): boolean;
        isPointerLocked(): boolean;
        lockPointer(lock: boolean): void;
        setCapturedPos(pos: Vector2): void;
        setMode(mode: MouseSetMode): void;
    }
    Index

    Methods

    • Returns boolean

      whether the pointer is visible.

    • True when pointer is locked to canvas.

      Returns boolean

    • Enable/disable pointer lock (capture).

      For more fine-grained control, use setMode which also documents behaviors more thoroughly.

      Parameters

      • lock: boolean

      Returns void

    • Only applicable in capture mode -- sets the position of the emulated mouse.

      Parameters

      Returns void

    • Set the current cursor mode.

      Consider setting scrollBlock to false (default is true) if you want your element to blend into the webpage for freer scrolling.

      {
      lock: false,
      visible: true, // disable to hide cursor.
      scrollBlock: true, // disable scroll while hovering canvas. Default: true
      }

      In locked mode, the cursor cannot escape the canvas. It also becomes invisible. However, it can move infinitely, sensitivity can be controlled, and the emulated cursor (in pos of index.LikeHandlers.mousemoved) can be freely repositioned.

      {
      lock: true,
      speed: 1.0, // mouse sensitivity
      }

      Avoid binding the ESC key in captured mode. This will exit the capture and reset mode to default.

      Event index.LikeHandlers.mousemoved passes both pos and delta args.

      Though the emulated cursor in locked mode (locked mode doesn't natively track absolute position) may be stuck on canvas edges, the delta field always represents mouse movement, even against edges.

      Parameters

      Returns void

    Properties

    setRelativeMode?: undefined

    I beleve you wanted to use like.mouse.setMode({lock: true}) or `like.mouse.lockPointer().