crystal.input.current_mouse_target
Advanced
Returns the mouse target the mouse pointer is currently on top of.
This function should rarely be needed, as Crystal UI elements and mouse areas offer higher level constructs to implement mouse interactions.
Usage
crystal.input.current_mouse_target()
Returns
| Name | Type | Description |
|---|---|---|
recipient | table | nil | A recipient table that was previously registered via add_mouse_target. nil if the mouse is not currently on top of a mouse target. |
Examples
This example defines a scene with an interactive mouse object in the top left of the game window.
local Scene = Class("MyScene", crystal.Scene);
Scene.init = function(self)
self.clickable_box = { name = "Cardboard box" };
end
Scene.update = function(self)
local under_mouse = crystal.input.current_mouse_target();
if under_mouse then
print(under_mouse.name); -- Prints "Cardboard box" while the mouse is within the top left of the game window
end
end
Scene.draw = function(self)
crystal.input.add_mouse_target(self.clickable_box, 0, 100, 0, 100);
end