Discord

Preparing your files

Please wait until the download is ready.

Luka's Scripting Utilities

Luka's Scripting Utilities

by Luka S.J.

A pack full of various scripting utilities to ease your development!

v4.1.135,194
Download144 KB

Mouse Input

The Mouse module wraps mkxp-z mouse handling into a friendly API, and extends
Sprite, Viewport and Rect with hit-testing and dragging helpers. A press
counts as a click when it is released within Mouse::CLICK_TIMEOUT (0.5 s).

All button arguments accept :left (default), :right or :middle.

Cursor state

  • Mouse.active? whether the cursor is inside the game window
  • Mouse.show / Mouse.hide show or hide the system cursor

Buttons

  • Mouse.click?(button = :left) pressed and released within the click timeout
  • Mouse.press?(button = :left) currently pressed
  • Mouse.release?(button = :left) just released
  • Mouse.repeat?(button = :left) input is repeating
  • Mouse.hold?(button) held longer than the click timeout

Wheel

  • Mouse.scroll_up?(rect = nil) wheel scrolled up (optionally only while over rect)
  • Mouse.scroll_down?(rect = nil) wheel scrolled down (optionally only while over rect)

Hit testing

  • Mouse.over?(object) whether the cursor is over an object (the object must respond to mouse_params)
  • Mouse.over_area?(x, y, w, h) whether the cursor is within an arbitrary rectangle
  • Mouse.create_rect(button = :left) build a Rect from a click-and-drag selection (empty when not dragging)

Dragging

  • Mouse.dragging?(object, button = :left) whether the object is currently being dragged
  • Mouse.drag_object(object, button = :left, rect = nil, lock = nil) drag the object to follow the cursor, optionally bounded by rect and locked to :horizontal or :vertical
  • Mouse.drag_object_x(object, ...) / Mouse.drag_object_y(object, ...) drag on one axis only

Object extensions

Sprite, Viewport and Rect gain the following (each computes its own
on-screen mouse_params):

  • object.over? cursor is over the object
  • object.click? object was clicked
  • object.press? mouse is pressed over the object
  • object.mouse_drag(rect = nil) drag with the left button (also mouse_drag_x / mouse_drag_y)
  • object.overlap?(target) this object's area overlaps the target's
  • object.released_in?(target) mouse released while overlapping the target
  • object.released_in_rect?(target) mouse released while this object's position falls inside the target rect

Sprites additionally provide:

  • sprite.over_pixel? cursor is over a non-transparent pixel (alpha-aware hit testing)
if @button.click?
  do_thing
elsif @icon.over_pixel?
  @icon.colorize(Color.yellow, amount: 80)
end