World > Mouse#

API Reference#

class miniworlds.worlds.manager.mouse_manager.MouseManager(world)[Quellcode]#

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)[Quellcode]#

Initialize the MouseManager.

Parameter:

world – The world instance this mouse belongs to.

get_last_position()[Quellcode]#

Returns the mouse position from the last frame (if available).

Rückgabetyp:

Optional[Tuple[int, int]]

Examples

>>> last = world.mouse.get_last_position()
get_position()[Quellcode]#

Gets the current mouse position if the mouse is over this world.

Rückgabetyp:

Optional[Tuple[int, int]]

Rückgabe:

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()[Quellcode]#

Returns True if the left mouse button is pressed.

Rückgabetyp:

bool

Examples

>>> if world.mouse.is_mouse_left_pressed():
...     print("Left click detected")
is_mouse_pressed()[Quellcode]#

Returns True if any mouse button (left or right) is currently pressed.

Rückgabetyp:

bool

Examples

>>> if world.mouse.is_mouse_pressed():
...     print("Mouse is down")
is_mouse_right_pressed()[Quellcode]#

Returns True if the right mouse button is pressed.

Rückgabetyp:

bool

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()[Quellcode]#

Returns True if the left mouse button is currently pressed.

Rückgabetyp:

bool

Examples

>>> if world.mouse.left():
...     print("Left button is down")
mouse_left_is_clicked()[Quellcode]#

Backward-compatible alias for checking the left mouse button.

Rückgabetyp:

bool

mouse_right_is_clicked()[Quellcode]#

Backward-compatible alias for checking the right mouse button.

Rückgabetyp:

bool

property position: Tuple[int, int] | None#

Property version of get_position()

Examples

>>> if world.mouse.position:
...     print("Mouse is on world!")
right()[Quellcode]#

Returns True if the right mouse button is currently pressed.

Rückgabetyp:

bool

Examples

>>> if world.mouse.right():
...     print("Right button is down")
x()[Quellcode]#

Returns the x-coordinate of the mouse if over the world, otherwise 0.

Rückgabetyp:

int

Examples

>>> x = world.mouse.x()
y()[Quellcode]#

Returns the y-coordinate of the mouse if over the world, otherwise 0.

Rückgabetyp:

int

Examples

>>> y = world.mouse.y()