World > Mouse#
- 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_mouse_position() >>> world.mouse.is_mouse_left_pressed()
Public Data Attributes:
Property version of get_mouse_position()
Returns the mouse position from the previous frame.
Public Methods:
__init__
(world)Initialize the MouseManager.
Gets the current mouse position if the mouse is over this world.
left
()Returns True if the left mouse button is currently pressed.
right
()Returns True if the right mouse button is currently pressed.
x
()Returns the x-coordinate of the mouse if over the world, otherwise 0.
y
()Returns the y-coordinate of the mouse if over the world, otherwise 0.
Returns the mouse position from the last frame (if available).
Returns True if any mouse button (left or right) is currently pressed.
Returns True if the left mouse button is pressed.
Returns True if the right mouse button is pressed.
Private Methods:
_update_positions
()Updates the current and previous mouse positions.
- __init__(world)[source]#
Initialize the MouseManager.
- Parameters:
world – The world instance this mouse belongs to.
- get_mouse_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_mouse_position() >>> if pos: ... print("Mouse over world at", pos)
- get_prev_mouse_position()[source]#
Returns the mouse position from the last frame (if available).
Examples
>>> last = world.mouse.get_prev_mouse_position()
- 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")
- left()[source]#
Returns True if the left mouse button is currently pressed.
- Return type:
Examples
>>> if world.mouse.mouse_left_is_clicked(): ... print("Left button is down")
- property mouse_position: Tuple[int, int] | None#
Property version of get_mouse_position()
Examples
>>> if world.mouse.mouse_position: ... print("Mouse is on world!")
- property prev_mouse_position: Tuple[int, int] | None#
Returns the mouse position from the previous frame.
Examples
>>> prev = world.mouse.prev_mouse_position >>> if prev: ... print("Mouse was at:", prev)
- right()[source]#
Returns True if the right mouse button is currently pressed.
- Return type:
Examples
>>> if world.mouse.mouse_right_is_clicked(): ... print("Right button is down")