World > Mouse#
API Reference#
- class miniworlds.worlds.manager.mouse_manager.MouseManager(world)[source]#
Manages mouse input for a given world. Provides access to current mouse position, click states, and previous mouse state.
- Usage:
>>> world.mouse.get_position() >>> world.mouse.is_left()
- __init__(world)[source]#
Initialize the MouseManager.
- Parameters:
world – The world instance this mouse belongs to.
- get_last_position()[source]#
Returns the mouse position from the last frame (if available).
Examples
>>> last = world.mouse.get_last_position()
- get_position()[source]#
Gets the current mouse position if the mouse is over this world.
- Return type:
- Returns:
Tuple of (x, y) coordinates or None if mouse is not on this world.
Examples
>>> pos = world.mouse.get_position() >>> if pos: ... print("Mouse over world at", pos)
- is_mouse_left_pressed()[source]#
Returns True if the left mouse button is pressed.
- Return type:
Examples
>>> if world.mouse.is_mouse_left_pressed(): ... print("Left click detected")
- is_mouse_pressed()[source]#
Returns True if any mouse button (left or right) is currently pressed.
- Return type:
Examples
>>> if world.mouse.is_mouse_pressed(): ... print("Mouse is down")
- is_mouse_right_pressed()[source]#
Returns True if the right mouse button is pressed.
- Return type:
Examples
>>> if world.mouse.is_mouse_right_pressed(): ... print("Right click detected")
- property last_position: Tuple[int, int] | None#
Returns the mouse position from the previous frame.
Examples
>>> prev = world.mouse.last_mouse_position >>> if prev: ... print("Mouse was at:", prev)
- left()[source]#
Returns True if the left mouse button is currently pressed.
- Return type:
Examples
>>> if world.mouse.left(): ... print("Left button is down")
- mouse_left_is_clicked()[source]#
Backward-compatible alias for checking the left mouse button.
- Return type:
- mouse_right_is_clicked()[source]#
Backward-compatible alias for checking the right mouse button.
- Return type:
- property position: Tuple[int, int] | None#
Property version of get_position()
Examples
>>> if world.mouse.position: ... print("Mouse is on world!")
- right()[source]#
Returns True if the right mouse button is currently pressed.
- Return type:
Examples
>>> if world.mouse.right(): ... print("Right button is down")