Skip to main content

Mouse

The Mouse class is a singleton class that handles mouse input.

info

Prefer to get the unique instance of this service from the ServiceContainer like:

const mouse = ServiceContainer.mouse;

Getters​

instance​

  • Type: Mouse

Get the instance of mouse service.

position​

  • Type: Point

Get the position of the mouse on the canvas.


Methods​

isDown​

prototype
isDown(button: MouseButton): boolean;

Check if a button is down.

Parameters​

  • button
    • Type: MouseButton
    • The button to check.

Return​

boolean - true if the button is down, false otherwise.

Example​

ServiceContainer.Mouse.isDown(MouseButton.Left);

isUp​

prototype
isUp(button: MouseButton): boolean;

Check if a key is up.

Parameters​

  • button
    • Type: MouseButton
    • The button to check.

Return​

boolean - true if the button is up, false otherwise.

Example​

ServiceContainer.Mouse.isUp(MouseButton.Left);

isJustDown​

prototype
isJustDown(button: MouseButton): boolean;

Check if a button is just down during the current frame.

Parameters​

  • button
    • Type: MouseButton
    • The button to check.

Return​

boolean - true if the button is just down down, false otherwise.

Example​

ServiceContainer.Mouse.isJustDown(MouseButton.Left);

isJustUp​

prototype
isJustUp(button: MouseButton): boolean;

Check if a button is just up during the current frame.

Parameters​

  • button
    • Type: MouseButton
    • The button to check.

Return​

boolean - true if the button is just up, false otherwise.

Example​

ServiceContainer.Mouse.isJustUp(MouseButton.Left);

setCursor​

prototype
setCursor(image: string, offset: Point | number): Mouse;

Set the cursor image.

Parameters​

  • image

    • Type: string
    • The image to use for the cursor.
  • offset

    • Type: Point | number
    • The offset of the cursor.

Return​

Mouse The mouse service.

Examples​

ServiceContainer.Mouse.setCursor('cursor.png', 0);
ServiceContainer.Mouse.setCursor('cursor.png', new Point(0, 0));