World > Mouse#

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_mouse_position()
>>> world.mouse.is_mouse_left_pressed()

Public Data Attributes:

mouse_position

Property version of get_mouse_position()

prev_mouse_position

Returns the mouse position from the previous frame.

Public Methods:

__init__(world)

Initialize the MouseManager.

get_mouse_position()

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.

get_prev_mouse_position()

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

is_mouse_pressed()

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

is_mouse_left_pressed()

Returns True if the left mouse button is pressed.

is_mouse_right_pressed()

Returns True if the right mouse button is pressed.

Private Methods:

_update_positions()

Updates the current and previous mouse positions.


__init__(world)[Quellcode]#

Initialize the MouseManager.

Parameter:

world – The world instance this mouse belongs to.

get_mouse_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_mouse_position()
>>> if pos:
...     print("Mouse over world at", pos)
get_prev_mouse_position()[Quellcode]#

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

Rückgabetyp:

Optional[Tuple[int, int]]

Examples

>>> last = world.mouse.get_prev_mouse_position()
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")
left()[Quellcode]#

Returns True if the left mouse button is currently pressed.

Rückgabetyp:

bool

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

Returns True if the right mouse button is currently pressed.

Rückgabetyp:

bool

Examples

>>> if world.mouse.mouse_right_is_clicked():
...     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.get_mouse_y()