-`handler`: Function called with (runtime: float) parameter
-`interval`: Time between calls in milliseconds
**Returns:** None If a timer with this name exists, it will be replaced. The handler receives the total runtime in seconds as its argument.
### `start_benchmark() -> None`
Start capturing benchmark data to a file.
Note:
**Returns:** None
**Raises:** RuntimeError: If a benchmark is already running Benchmark filename is auto-generated from PID and timestamp. Use end_benchmark() to stop and get filename.
### `step(dt: float = None) -> float`
Advance simulation time (headless mode only).
Note:
**Arguments:**
-`dt`: Time to advance in seconds. If None, advances to the next scheduled event (timer/animation).
**Returns:** float: Actual time advanced in seconds. Returns 0.0 in windowed mode. In windowed mode, this is a no-op and returns 0.0. Use this for deterministic simulation control in headless/testing scenarios.
Complete the animation immediately by jumping to the final value.
Note:
**Returns:** None Sets elapsed = duration and applies target value immediately. Completion callback will be called if set.
#### `get_current_value() -> Any`
Get the current interpolated value of the animation.
Note:
**Returns:** Any: Current value (type depends on property: float, int, Color tuple, Vector tuple, or str) Return type matches the target property type. For sprite_index returns int, for pos returns (x, y), for fill_color returns (r, g, b, a).
#### `hasValidTarget() -> bool`
Check if the animation still has a valid target.
Note:
**Returns:** bool: True if the target still exists, False if it was destroyed Animations automatically clean up when targets are destroyed. Use this to check if manual cleanup is needed.
-`target`: The UI element to animate (Frame, Caption, Sprite, Grid, or Entity)
-`conflict_mode`: How to handle conflicts if property is already animating: 'replace' (default) - complete existing animation and start new one; 'queue' - wait for existing animation to complete; 'error' - raise RuntimeError if property is busy
**Returns:** None
**Raises:** RuntimeError: When conflict_mode='error' and property is already animating The animation will automatically stop if the target is destroyed.
#### `update(delta_time: float) -> bool`
Update the animation by the given time delta.
Note:
**Arguments:**
-`delta_time`: Time elapsed since last update in seconds
**Returns:** bool: True if animation is still running, False if complete Typically called by AnimationManager automatically. Manual calls only needed for custom animation control.
-`bounds`: Bounding rectangle (x, y, width, height) in local coordinates.
-`center`: Center position of the arc
-`color`: Arc color
-`end_angle`: Ending angle in degrees
-`global_bounds`: Bounding rectangle (x, y, width, height) in screen coordinates.
-`global_position`*(read-only)*: Global screen position (read-only). Calculates absolute position by walking up the parent chain.
-`hovered`*(read-only)*: Whether mouse is currently over this element (read-only). Updated automatically by the engine during mouse movement.
-`name`: Name for finding this element.
-`on_click`: Callable executed when arc is clicked.
-`on_enter`: Callback for mouse enter events. Called with (x, y, button, action) when mouse enters this element's bounds.
-`on_exit`: Callback for mouse exit events. Called with (x, y, button, action) when mouse leaves this element's bounds.
-`on_move`: Callback for mouse movement within bounds. Called with (x, y, button, action) for each mouse movement while inside. Performance note: Called frequently during movement - keep handlers fast.
-`opacity`: Opacity level (0.0 = transparent, 1.0 = opaque). Automatically clamped to valid range [0.0, 1.0].
-`parent`: Parent drawable. Get: Returns the parent Frame/Grid if nested, or None if at scene level. Set: Assign a Frame/Grid to reparent, or None to remove from parent.
-`pos`: Position as a Vector (same as center).
-`radius`: Arc radius in pixels
-`start_angle`: Starting angle in degrees
-`thickness`: Line thickness
-`visible`: Whether the object is visible (bool). Invisible objects are not rendered or clickable.
-`z_index`: Z-order for rendering (lower values rendered first).
Get the bounding rectangle of this drawable element.
Note:
**Returns:** tuple: (x, y, width, height) representing the element's bounds The bounds are in screen coordinates and account for current position and size.
-`bounds`: Bounding rectangle (x, y, width, height) in local coordinates.
-`fill_color`: Fill color of the text
-`font_size`: Font size (integer) in points
-`global_bounds`: Bounding rectangle (x, y, width, height) in screen coordinates.
-`global_position`*(read-only)*: Global screen position (read-only). Calculates absolute position by walking up the parent chain.
-`hovered`*(read-only)*: Whether mouse is currently over this element (read-only). Updated automatically by the engine during mouse movement.
-`name`: Name for finding elements
-`on_click`: Callable executed when object is clicked. Function receives (x, y) coordinates of click.
-`on_enter`: Callback for mouse enter events. Called with (x, y, button, action) when mouse enters this element's bounds.
-`on_exit`: Callback for mouse exit events. Called with (x, y, button, action) when mouse leaves this element's bounds.
-`on_move`: Callback for mouse movement within bounds. Called with (x, y, button, action) for each mouse movement while inside. Performance note: Called frequently during movement - keep handlers fast.
-`opacity`: Opacity level (0.0 = transparent, 1.0 = opaque). Automatically clamped to valid range [0.0, 1.0].
-`outline`: Thickness of the border
-`outline_color`: Outline color of the text
-`parent`: Parent drawable. Get: Returns the parent Frame/Grid if nested, or None if at scene level. Set: Assign a Frame/Grid to reparent, or None to remove from parent.
-`pos`: (x, y) vector
-`text`: The text displayed
-`visible`: Whether the object is visible (bool). Invisible objects are not rendered or clickable.
-`x`: X coordinate of top-left corner
-`y`: Y coordinate of top-left corner
-`z_index`: Z-order for rendering (lower values rendered first). Automatically triggers scene resort when changed.
Get the bounding rectangle of this drawable element.
Note:
**Returns:** tuple: (x, y, width, height) representing the element's bounds The bounds are in screen coordinates and account for current position and size.
-`bounds`: Bounding rectangle (x, y, width, height) in local coordinates.
-`center`: Center position of the circle
-`fill_color`: Fill color of the circle
-`global_bounds`: Bounding rectangle (x, y, width, height) in screen coordinates.
-`global_position`*(read-only)*: Global screen position (read-only). Calculates absolute position by walking up the parent chain.
-`hovered`*(read-only)*: Whether mouse is currently over this element (read-only). Updated automatically by the engine during mouse movement.
-`name`: Name for finding this element.
-`on_click`: Callable executed when circle is clicked.
-`on_enter`: Callback for mouse enter events. Called with (x, y, button, action) when mouse enters this element's bounds.
-`on_exit`: Callback for mouse exit events. Called with (x, y, button, action) when mouse leaves this element's bounds.
-`on_move`: Callback for mouse movement within bounds. Called with (x, y, button, action) for each mouse movement while inside. Performance note: Called frequently during movement - keep handlers fast.
-`opacity`: Opacity level (0.0 = transparent, 1.0 = opaque). Automatically clamped to valid range [0.0, 1.0].
-`outline`: Outline thickness (0 for no outline)
-`outline_color`: Outline color of the circle
-`parent`: Parent drawable. Get: Returns the parent Frame/Grid if nested, or None if at scene level. Set: Assign a Frame/Grid to reparent, or None to remove from parent.
-`pos`: Position as a Vector (same as center).
-`radius`: Circle radius in pixels
-`visible`: Whether the object is visible (bool). Invisible objects are not rendered or clickable.
-`z_index`: Z-order for rendering (lower values rendered first).
Get the bounding rectangle of this drawable element.
Note:
**Returns:** tuple: (x, y, width, height) representing the element's bounds The bounds are in screen coordinates and account for current position and size.
Get the bounding rectangle of this drawable element.
Note:
**Returns:** tuple: (x, y, width, height) representing the element's bounds The bounds are in screen coordinates and account for current position and size.
Get the bounding rectangle of this drawable element.
Note:
**Returns:** tuple: (x, y, width, height) representing the element's bounds The bounds are in screen coordinates and account for current position and size.
#### `index(...)`
Return the index of this entity in its grid's entity collection
#### `move(dx: float, dy: float) -> None`
Move the element by a relative offset.
Note:
**Arguments:**
-`dx`: Horizontal offset in pixels
-`dy`: Vertical offset in pixels
#### `path_to(x: int, y: int) -> bool`
Find and follow path to target position using A* pathfinding.
**Arguments:**
-`x`: Target X coordinate
-`y`: Target Y coordinate
**Returns:** True if a path was found and the entity started moving, False otherwise The entity will automatically move along the path over multiple frames. Call this again to change the target or repath.
Get list of other entities visible from this entity's position.
**Returns:** List of Entity objects that are within field of view. Computes FOV from this entity's position and returns all other entities whose positions fall within the visible area.
### EntityCollection
Iterable, indexable collection of Entities
**Methods:**
#### `append(entity)`
Add an entity to the end of the collection.
#### `count(entity) -> int`
Count occurrences of entity in the collection.
#### `extend(iterable)`
Add all entities from an iterable to the collection.
#### `find(name) -> entity or list`
Find entities by name.
**Returns:** Single entity if exact match, list if wildcard, None if not found.
#### `index(entity) -> int`
Return index of first occurrence of entity. Raises ValueError if not found.
#### `insert(index, entity)`
Insert entity at index. Like list.insert(), indices past the end append.
#### `pop([index]) -> entity`
Remove and return entity at index (default: last entity).
#### `remove(entity)`
Remove first occurrence of entity. Raises ValueError if not found.
-`bounds`: Bounding rectangle (x, y, width, height) in local coordinates.
-`cache_subtree`: #144: Cache subtree rendering to texture for performance
-`children`: UICollection of objects on top of this one
-`clip_children`: Whether to clip children to frame bounds
-`fill_color`: Fill color of the rectangle
-`global_bounds`: Bounding rectangle (x, y, width, height) in screen coordinates.
-`global_position`*(read-only)*: Global screen position (read-only). Calculates absolute position by walking up the parent chain.
-`h`: height of the rectangle
-`hovered`*(read-only)*: Whether mouse is currently over this element (read-only). Updated automatically by the engine during mouse movement.
-`name`: Name for finding elements
-`on_click`: Callable executed when object is clicked. Function receives (x, y) coordinates of click.
-`on_enter`: Callback for mouse enter events. Called with (x, y, button, action) when mouse enters this element's bounds.
-`on_exit`: Callback for mouse exit events. Called with (x, y, button, action) when mouse leaves this element's bounds.
-`on_move`: Callback for mouse movement within bounds. Called with (x, y, button, action) for each mouse movement while inside. Performance note: Called frequently during movement - keep handlers fast.
-`opacity`: Opacity level (0.0 = transparent, 1.0 = opaque). Automatically clamped to valid range [0.0, 1.0].
-`outline`: Thickness of the border
-`outline_color`: Outline color of the rectangle
-`parent`: Parent drawable. Get: Returns the parent Frame/Grid if nested, or None if at scene level. Set: Assign a Frame/Grid to reparent, or None to remove from parent.
-`pos`: Position as a Vector
-`visible`: Whether the object is visible (bool). Invisible objects are not rendered or clickable.
-`w`: width of the rectangle
-`x`: X coordinate of top-left corner
-`y`: Y coordinate of top-left corner
-`z_index`: Z-order for rendering (lower values rendered first). Automatically triggers scene resort when changed.
Get the bounding rectangle of this drawable element.
Note:
**Returns:** tuple: (x, y, width, height) representing the element's bounds The bounds are in screen coordinates and account for current position and size.
-`bounds`: Bounding rectangle (x, y, width, height) in local coordinates.
-`center`: Grid coordinate at the center of the Grid's view (pan)
-`center_x`: center of the view X-coordinate
-`center_y`: center of the view Y-coordinate
-`children`: UICollection of UIDrawable children (speech bubbles, effects, overlays)
-`entities`: EntityCollection of entities on this grid
-`fill_color`: Background fill color of the grid
-`fov`: FOV algorithm for this grid (mcrfpy.FOV enum). Used by entity.updateVisibility() and layer methods when fov=None.
-`fov_radius`: Default FOV radius for this grid. Used when radius not specified.
-`global_bounds`: Bounding rectangle (x, y, width, height) in screen coordinates.
-`global_position`*(read-only)*: Global screen position (read-only). Calculates absolute position by walking up the parent chain.
-`grid_size`: Grid dimensions (grid_x, grid_y)
-`grid_x`: Grid x dimension
-`grid_y`: Grid y dimension
-`h`: visible widget height
-`hovered`*(read-only)*: Whether mouse is currently over this element (read-only). Updated automatically by the engine during mouse movement.
-`hovered_cell`: Currently hovered cell as (x, y) tuple, or None if not hovering.
-`layers`: List of grid layers (ColorLayer, TileLayer) sorted by z_index
-`name`: Name for finding elements
-`on_cell_click`: Callback when a grid cell is clicked. Called with (cell_x, cell_y).
-`on_cell_enter`: Callback when mouse enters a grid cell. Called with (cell_x, cell_y).
-`on_cell_exit`: Callback when mouse exits a grid cell. Called with (cell_x, cell_y).
-`on_click`: Callable executed when object is clicked. Function receives (x, y) coordinates of click.
-`on_enter`: Callback for mouse enter events. Called with (x, y, button, action) when mouse enters this element's bounds.
-`on_exit`: Callback for mouse exit events. Called with (x, y, button, action) when mouse leaves this element's bounds.
-`on_move`: Callback for mouse movement within bounds. Called with (x, y, button, action) for each mouse movement while inside. Performance note: Called frequently during movement - keep handlers fast.
-`opacity`: Opacity level (0.0 = transparent, 1.0 = opaque). Automatically clamped to valid range [0.0, 1.0].
-`parent`: Parent drawable. Get: Returns the parent Frame/Grid if nested, or None if at scene level. Set: Assign a Frame/Grid to reparent, or None to remove from parent.
-`perspective`: Entity whose perspective to use for FOV rendering (None for omniscient view). Setting an entity automatically enables perspective mode.
-`perspective_enabled`: Whether to use perspective-based FOV rendering. When True with no valid entity, all cells appear undiscovered.
-`pos`: Position of the grid as Vector
-`position`: Position of the grid (x, y)
-`size`: Size of the grid (width, height)
-`texture`: Texture of the grid
-`visible`: Whether the object is visible (bool). Invisible objects are not rendered or clickable.
-`w`: visible widget width
-`x`: top-left corner X-coordinate
-`y`: top-left corner Y-coordinate
-`z_index`: Z-order for rendering (lower values rendered first). Automatically triggers scene resort when changed.
-`diagonal_cost`: Cost of diagonal movement (default: 1.41)
**Returns:** List of (x, y) tuples representing the path, empty list if no path exists Alternative A* implementation. Prefer find_path() for consistency.
-`diagonal_cost`: Cost of diagonal movement (default: 1.41)
**Returns:** List of (x, y) tuples representing the path, empty list if no path exists Uses A* algorithm with walkability from grid cells.
#### `get_bounds() -> tuple`
Get the bounding rectangle of this drawable element.
Note:
**Returns:** tuple: (x, y, width, height) representing the element's bounds The bounds are in screen coordinates and account for current position and size.
**Returns:** List of (x, y) tuples representing path to root, empty if unreachable Must call compute_dijkstra() first. Path includes start but not root position.
#### `is_in_fov(x: int, y: int) -> bool`
Check if a cell is in the field of view.
**Arguments:**
-`x`: X coordinate to check
-`y`: Y coordinate to check
**Returns:** True if the cell is visible, False otherwise Must call compute_fov() first to calculate visibility.
-`bounds`: Bounding rectangle (x, y, width, height) in local coordinates.
-`color`: Line color as a Color object.
-`end`: Ending point of the line as a Vector.
-`global_bounds`: Bounding rectangle (x, y, width, height) in screen coordinates.
-`global_position`*(read-only)*: Global screen position (read-only). Calculates absolute position by walking up the parent chain.
-`hovered`*(read-only)*: Whether mouse is currently over this element (read-only). Updated automatically by the engine during mouse movement.
-`name`: Name for finding this element.
-`on_click`: Callable executed when line is clicked.
-`on_enter`: Callback for mouse enter events. Called with (x, y, button, action) when mouse enters this element's bounds.
-`on_exit`: Callback for mouse exit events. Called with (x, y, button, action) when mouse leaves this element's bounds.
-`on_move`: Callback for mouse movement within bounds. Called with (x, y, button, action) for each mouse movement while inside. Performance note: Called frequently during movement - keep handlers fast.
-`opacity`: Opacity level (0.0 = transparent, 1.0 = opaque). Automatically clamped to valid range [0.0, 1.0].
-`parent`: Parent drawable. Get: Returns the parent Frame/Grid if nested, or None if at scene level. Set: Assign a Frame/Grid to reparent, or None to remove from parent.
-`pos`: Position as a Vector (midpoint of line).
-`start`: Starting point of the line as a Vector.
-`thickness`: Line thickness in pixels.
-`visible`: Whether the object is visible (bool). Invisible objects are not rendered or clickable.
-`z_index`: Z-order for rendering (lower values rendered first).
Get the bounding rectangle of this drawable element.
Note:
**Returns:** tuple: (x, y, width, height) representing the element's bounds The bounds are in screen coordinates and account for current position and size.
-`active`*(read-only)*: Whether this scene is currently active (bool, read-only). Only one scene can be active at a time.
-`children`*(read-only)*: UI element collection for this scene (UICollection, read-only). Use to add, remove, or iterate over UI elements. Changes are reflected immediately.
-`name`*(read-only)*: Scene name (str, read-only). Unique identifier for this scene.
-`on_key`: Keyboard event handler (callable or None). Function receives (key: str, action: str) for keyboard events. Set to None to remove the handler.
-`opacity`: Scene opacity (0.0-1.0). Applied to all UI elements during rendering.
-`pos`: Scene position offset (Vector). Applied to all UI elements during rendering.
-`visible`: Scene visibility (bool). If False, scene is not rendered.
-`bounds`: Bounding rectangle (x, y, width, height) in local coordinates.
-`global_bounds`: Bounding rectangle (x, y, width, height) in screen coordinates.
-`global_position`*(read-only)*: Global screen position (read-only). Calculates absolute position by walking up the parent chain.
-`hovered`*(read-only)*: Whether mouse is currently over this element (read-only). Updated automatically by the engine during mouse movement.
-`name`: Name for finding elements
-`on_click`: Callable executed when object is clicked. Function receives (x, y) coordinates of click.
-`on_enter`: Callback for mouse enter events. Called with (x, y, button, action) when mouse enters this element's bounds.
-`on_exit`: Callback for mouse exit events. Called with (x, y, button, action) when mouse leaves this element's bounds.
-`on_move`: Callback for mouse movement within bounds. Called with (x, y, button, action) for each mouse movement while inside. Performance note: Called frequently during movement - keep handlers fast.
-`opacity`: Opacity level (0.0 = transparent, 1.0 = opaque). Automatically clamped to valid range [0.0, 1.0].
-`parent`: Parent drawable. Get: Returns the parent Frame/Grid if nested, or None if at scene level. Set: Assign a Frame/Grid to reparent, or None to remove from parent.
-`pos`: Position as a Vector
-`scale`: Uniform size factor
-`scale_x`: Horizontal scale factor
-`scale_y`: Vertical scale factor
-`sprite_index`: Which sprite on the texture is shown
-`sprite_number`: Sprite index (DEPRECATED: use sprite_index instead)
-`texture`: Texture object
-`visible`: Whether the object is visible (bool). Invisible objects are not rendered or clickable.
-`x`: X coordinate of top-left corner
-`y`: Y coordinate of top-left corner
-`z_index`: Z-order for rendering (lower values rendered first). Automatically triggers scene resort when changed.
Get the bounding rectangle of this drawable element.
Note:
**Returns:** tuple: (x, y, width, height) representing the element's bounds The bounds are in screen coordinates and account for current position and size.
-`filename`: Optional path to save screenshot. If omitted, returns raw RGBA bytes.
**Returns:** bytes | None: Raw RGBA pixel data if no filename given, otherwise None after saving Screenshot is taken at the actual window resolution. Use after render loop update for current frame.