Mouse Cursor - Grisgram/gml-raptor GitHub Wiki
Base Controls - Containers - Tooltips - Clickables - Checkables - ListBox - InputBox - ✔Mouse Cursor
- ControlTree
The MouseCursor
object is a small and simple object, that aligns itself with the mouse position each frame.
The origin
of the sprite is the focus point, the coordinate where the "click" happens.
You simply drag a MouseCursor
to your room, it will adapt its depth (to be top-most) automatically and it will work fully transparent.
However, of course it offers some functions to interact with, to change its sprite or add a companion.
The object offers a #macro MOUSE_CURSOR
which will always point to the active instance of the mouse cursor or return undefined
, if no MouseCursor
is active in the room.
Note
Your interaction with the MouseCursor object should always be through MOUSE_CURSOR.*
!
Set a different cursor to use. raptor
comes with predefined sprites for pointing and sizing cursors. Of couse you can create your own.
/// @function set_cursor(_mouse_cursor_type, _mouse_cursor_sizing = 0)
/// @param {enum} _mouse_cursor_type One of: mouse_cursor_type.pointer, mouse_cursor_type.sizing
/// @param {enum} _mouse_cursor_sizing Optional. If type is sizing, use one of these enum values:
/// mouse_cursor_sizing.we, ns, nwse or nesw
/// These enums are named similar to GameMaker's mouse cursors
set_cursor = function(_mouse_cursor_type, _mouse_cursor_sizing = 0) {
/// @function set_cursor_custom(_cursor_sprite)
/// @description Sets any custom sprite to be the mouse cursor sprite.
/// This will also set "mouse_cursor_type.pointer".
/// To reset to the default pointer cursor, invoke set_cursor(mouse_cursor_type.pointer).
/// @param {sprite_index} _cursor_sprite The sprite to set as the active mouse cursor
set_cursor_custom = function(_cursor_sprite) {
This is simply because I wanted to give you a comfortable way to create an animated mouse cursor for your game. While the sprite with the sizing arrows will not be animated in most situations, there are many games that have at least a little animation on the default mouse cursor.
That's why they are seperated. The arrow received its own sprite to be easily replaceable with an animated version.
A MouseCursorCompanion
is a second object you can attach to the MouseCursor. It will be displayed at the right side, vertically centered, of the MouseCursor. You may know this from Windows, it's called "Background activity" there, in older Windows versions, there has often been a small hourglass displayed next to the cursor, or some loading animation to signal the user, that there's something going on in the background.
Im games, however, we can use this in drag & drop operations to signal with some green/red icon, whether the mouse is over a valid or invalid position to drop the item, things like that.
+-----+ <-- Mouse Cursor
| |
| +-----+ <-- Companion, vertically centered, at the right edge of the cursor
| | |
+-----+ |
| |
+-----+
/// @function set_companion(_companion_sprite, _type = undefined)
/// @description MouseCursor object has a companion_type variable definition,
/// and if _type is undefined, the variable setting's value is used.
/// This parameter is here, if you need a DIFFERENT OBJECT TYPE for
/// the companion than the one set in the variable definition.
/// @param {enum} _companion_sprite create a companion and assign the _sprite to it
/// @param {enum} _type Optional. By default undefined.
set_companion = function(_companion_sprite, _type = undefined) {
/// @function clear_companion(reset_blend_color = true)
/// @param {enum} reset_blend_color True by default. If you had image_blend active,
/// this resets to c_white.
clear_companion = function(reset_blend_color = true) {
/// @function destroy()
/// @description Destroy the instance, set MOUSE_CURSOR to undefined and
/// set the window cursor back to cr_default
destroy = function() {
Base Controls - Containers - Tooltips - Clickables - Checkables - ListBox - InputBox - ✔Mouse Cursor
- ControlTree