MouseLib.js

From Spheriki

Jump to: navigation, search

MouseLib.js is a custom script written by Leon. The aim of this script is to simplify creating programs in sphere that require a mouse. It allows for changing the cursor image and 'hotspot' area, and processes mouse events for all three buttons, as well as double clicks for the left button. It also contains click detection for both rectangular and circular areas, making it effective to use when making buttons of any type. It can be used with or without credit from me, just have fun with it.

Download in zip form here.

Contents

Usage

Basically, just require the script, and use the included Mouse.update() method before FlipScreen() in any loop that you want the mouse to be processed.

Here is a simple example of how to use the script in your program...

RequireScript("MouseLib.js");
 
function game()
{
  while (!IsKeyPressed(KEY_ESCAPE))
  {
    Mouse.update();
    FlipScreen();
  }
}

Contents

The script contains the Mouse object, and an external general-use function.

  • IsAnyMouseButtonPressed()
    • Boolean; returns true if any mouse button is held.

Mouse Object

This is the main part of the script, it contains several properties and methods, described below.

Properties

  • Mouse.X
  • Mouse.Y
    • Sets or retrieves the X and Y position of the mouse.
  • Mouse.HotspotX
  • Mouse.HotspotY
    • Sets or retrieves the point on which the mouse cursor image registers a click.
  • Mouse.Cursor
    • Sets or retrieves the mouse's current cursor image
  • Mouse.DoubleClickDelay
    • Sets or retrieves the delay in milliseconds to wait for a possible double click after a single click.

Methods

  • Mouse.update()
    • Main function of script, must be called just before FlipScreen() to use MouseLib.js.
  • Mouse.ChangeCursor(cursor_image, hotspot_x, hotspot_y)
    • Sets a new cursor image and hotspot location.
  • Mouse.isOverRectangle(x, y, w, h)
    • Boolean; returns true if mouse is inside specified rectangular area.
  • Mouse.isOverCircle(centerX, centerY, radius)
    • Boolean; returns true if mouse is inside specified circular area.
  • Mouse.isLeftHeld()
  • Mouse.isRightHeld()
  • Mouse.isMiddleHeld()
    • Boolean; returns true if a specific mouse button is held.
  • Mouse.isLeftClicked()
  • Mouse.isRightClicked()
  • Mouse.isMiddleClicked()
    • Boolean; returns true if a specific mouse button is clicked.
  • Mouse.isDoubleClicked()
    • Boolean; returns true if the left mouse button is double clicked.
Personal tools