Generated on 2025-10-30 21:14:43
This documentation was dynamically generated from the compiled module.
createScene(name: str) -> NoneCreate a new empty scene. Note:
Returns: None
Raises: ValueError: If a scene with this name already exists The scene is created but not made active. Use setScene() to switch to it.
createSoundBuffer(filename: str) -> intLoad a sound effect from a file and return its buffer ID.
Returns: int: Buffer ID for use with playSound()
Raises: RuntimeError: If the file cannot be loaded
currentScene() -> strGet the name of the currently active scene.
Returns: str: Name of the current scene
delTimer(name: str) -> NoneStop and remove a timer. Note:
Returns: None No error is raised if the timer doesn't exist.
exit() -> NoneCleanly shut down the game engine and exit the application. Note:
Returns: None This immediately closes the window and terminates the program.
find(name: str, scene: str = None) -> UIDrawable | NoneFind the first UI element with the specified name. Note:
Returns: Frame, Caption, Sprite, Grid, or Entity if found; None otherwise Searches scene UI elements and entities within grids.
findAll(pattern: str, scene: str = None) -> listFind all UI elements matching a name pattern. Note:
Returns: list: All matching UI elements and entities
getMetrics() -> dictGet current performance metrics.
Returns: dict: Performance data with keys: frame_time (last frame duration in seconds), avg_frame_time (average frame time), fps (frames per second), draw_calls (number of draw calls), ui_elements (total UI element count), visible_elements (visible element count), current_frame (frame counter), runtime (total runtime in seconds)
getMusicVolume() -> intGet the current music volume level.
Returns: int: Current volume (0-100)
getSoundVolume() -> intGet the current sound effects volume level.
Returns: int: Current volume (0-100)
keypressScene(handler: callable) -> NoneSet the keyboard event handler for the current scene. Note:
Returns: None
loadMusic(filename: str) -> NoneLoad and immediately play background music from a file. Note:
Returns: None Only one music track can play at a time. Loading new music stops the current track.
playSound(buffer_id: int) -> NonePlay a sound effect using a previously loaded buffer.
Returns: None
Raises: RuntimeError: If the buffer ID is invalid
sceneUI(scene: str = None) -> listGet all UI elements for a scene.
Returns: list: All UI elements (Frame, Caption, Sprite, Grid) in the scene
Raises: KeyError: If the specified scene doesn't exist
setMusicVolume(volume: int) -> NoneSet the global music volume.
Returns: None
setScale(multiplier: float) -> NoneScale the game window size. Note:
Returns: None The internal resolution remains 1024x768, but the window is scaled. This is deprecated - use Window.resolution instead.
setScene(scene: str, transition: str = None, duration: float = 0.0) -> NoneSwitch to a different scene with optional transition effect.
Returns: None
Raises: KeyError: If the scene doesn't exist ValueError: If the transition type is invalid
setSoundVolume(volume: int) -> NoneSet the global sound effects volume.
Returns: None
setTimer(name: str, handler: callable, interval: int) -> NoneCreate or update a recurring timer. Note:
Returns: None If a timer with this name exists, it will be replaced. The handler receives the total runtime in seconds as its argument.
Animation object for animating UI properties
complete() -> NoneComplete 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() -> AnyGet 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() -> boolCheck 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.
start(target: UIDrawable) -> NoneStart the animation on a target UI element. Note:
Returns: None The animation will automatically stop if the target is destroyed. Call AnimationManager.update(delta_time) each frame to progress animations.
update(delta_time: float) -> boolUpdate the animation by the given time delta. Note:
Returns: bool: True if animation is still running, False if complete Typically called by AnimationManager automatically. Manual calls only needed for custom animation control.
Inherits from: Drawable
Caption(pos=None, font=None, text='', **kwargs) A text display UI element with customizable font and styling. Args: pos (tuple, optional): Position as (x, y) tuple. Default: (0, 0) font (Font, optional): Font object for text rendering. Default: engine default font text (str, optional): The text content to display. Default: '' Keyword Args: fill_color (Color): Text fill color. Default: (255, 255, 255, 255) outline_color (Color): Text outline color. Default: (0, 0, 0, 255) outline (float): Text outline thickness. Default: 0 font_size (float): Font size in points. Default: 16 click (callable): Click event handler. Default: None visible (bool): Visibility state. Default: True opacity (float): Opacity (0.0-1.0). Default: 1.0 z_index (int): Rendering order. Default: 0 name (str): Element name for finding. Default: None x (float): X position override. Default: 0 y (float): Y position override. Default: 0 Attributes: text (str): The displayed text content x, y (float): Position in pixels pos (Vector): Position as a Vector object font (Font): Font used for rendering font_size (float): Font size in points fill_color, outline_color (Color): Text appearance outline (float): Outline thickness click (callable): Click event handler visible (bool): Visibility state opacity (float): Opacity value z_index (int): Rendering order name (str): Element name w, h (float): Read-only computed size based on text and font
get_bounds() -> tupleGet 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.
move(dx: float, dy: float) -> NoneMove the element by a relative offset. Note:
resize(width: float, height: float) -> NoneResize the element to new dimensions. Note:
SFML Color Object
from_hex(hex_string: str) -> ColorCreate a Color from a hexadecimal string. Note:
Returns: Color: New Color object with values from hex string
Raises: ValueError: If hex string is not 6 or 8 characters (RGB or RGBA) This is a class method. Call as Color.from_hex('#FF0000')
lerp(other: Color, t: float) -> ColorLinearly interpolate between this color and another. Note:
Returns: Color: New Color representing the interpolated value All components (r, g, b, a) are interpolated independently
to_hex() -> strConvert this Color to a hexadecimal string. Note:
Returns: str: Hex string in format '#RRGGBB' or '#RRGGBBAA' (if alpha < 255) Alpha component is only included if not fully opaque (< 255)
Base class for all drawable UI elements
get_bounds() -> tupleGet 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.
move(dx: float, dy: float) -> NoneMove the element by a relative offset. Note:
resize(width: float, height: float) -> NoneResize the element to new dimensions. Note:
Entity(grid_pos=None, texture=None, sprite_index=0, **kwargs) A game entity that exists on a grid with sprite rendering. Args: grid_pos (tuple, optional): Grid position as (x, y) tuple. Default: (0, 0) texture (Texture, optional): Texture object for sprite. Default: default texture sprite_index (int, optional): Index into texture atlas. Default: 0 Keyword Args: grid (Grid): Grid to attach entity to. Default: None visible (bool): Visibility state. Default: True opacity (float): Opacity (0.0-1.0). Default: 1.0 name (str): Element name for finding. Default: None x (float): X grid position override. Default: 0 y (float): Y grid position override. Default: 0 Attributes: pos (tuple): Grid position as (x, y) tuple x, y (float): Grid position coordinates draw_pos (tuple): Pixel position for rendering gridstate (GridPointState): Visibility state for grid points sprite_index (int): Current sprite index visible (bool): Visibility state opacity (float): Opacity value name (str): Element name
at(...)die(...)Remove this entity from its grid
get_bounds() -> tupleGet 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) -> NoneMove the element by a relative offset. Note:
path_to(x: int, y: int) -> boolFind and follow path to target position using A* pathfinding.
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.
resize(width: float, height: float) -> NoneResize the element to new dimensions. Note:
update_visibility() -> NoneUpdate entity's visibility state based on current FOV. Recomputes which cells are visible from the entity's position and updates the entity's gridstate to track explored areas. This is called automatically when the entity moves if it has a grid with perspective set.
Iterable, indexable collection of Entities
append(...)count(...)extend(...)index(...)remove(...)SFML Font Object
Inherits from: Drawable
Frame(pos=None, size=None, **kwargs) A rectangular frame UI element that can contain other drawable elements. Args: pos (tuple, optional): Position as (x, y) tuple. Default: (0, 0) size (tuple, optional): Size as (width, height) tuple. Default: (0, 0) Keyword Args: fill_color (Color): Background fill color. Default: (0, 0, 0, 128) outline_color (Color): Border outline color. Default: (255, 255, 255, 255) outline (float): Border outline thickness. Default: 0 click (callable): Click event handler. Default: None children (list): Initial list of child drawable elements. Default: None visible (bool): Visibility state. Default: True opacity (float): Opacity (0.0-1.0). Default: 1.0 z_index (int): Rendering order. Default: 0 name (str): Element name for finding. Default: None x (float): X position override. Default: 0 y (float): Y position override. Default: 0 w (float): Width override. Default: 0 h (float): Height override. Default: 0 clip_children (bool): Whether to clip children to frame bounds. Default: False Attributes: x, y (float): Position in pixels w, h (float): Size in pixels pos (Vector): Position as a Vector object fill_color, outline_color (Color): Visual appearance outline (float): Border thickness click (callable): Click event handler children (list): Collection of child drawable elements visible (bool): Visibility state opacity (float): Opacity value z_index (int): Rendering order name (str): Element name clip_children (bool): Whether to clip children to frame bounds
get_bounds() -> tupleGet 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.
move(dx: float, dy: float) -> NoneMove the element by a relative offset. Note:
resize(width: float, height: float) -> NoneResize the element to new dimensions. Note:
Inherits from: Drawable
Grid(pos=None, size=None, grid_size=None, texture=None, **kwargs) A grid-based UI element for tile-based rendering and entity management. Args: pos (tuple, optional): Position as (x, y) tuple. Default: (0, 0) size (tuple, optional): Size as (width, height) tuple. Default: auto-calculated from grid_size grid_size (tuple, optional): Grid dimensions as (grid_x, grid_y) tuple. Default: (2, 2) texture (Texture, optional): Texture containing tile sprites. Default: default texture Keyword Args: fill_color (Color): Background fill color. Default: None click (callable): Click event handler. Default: None center_x (float): X coordinate of center point. Default: 0 center_y (float): Y coordinate of center point. Default: 0 zoom (float): Zoom level for rendering. Default: 1.0 perspective (int): Entity perspective index (-1 for omniscient). Default: -1 visible (bool): Visibility state. Default: True opacity (float): Opacity (0.0-1.0). Default: 1.0 z_index (int): Rendering order. Default: 0 name (str): Element name for finding. Default: None x (float): X position override. Default: 0 y (float): Y position override. Default: 0 w (float): Width override. Default: auto-calculated h (float): Height override. Default: auto-calculated grid_x (int): Grid width override. Default: 2 grid_y (int): Grid height override. Default: 2 Attributes: x, y (float): Position in pixels w, h (float): Size in pixels pos (Vector): Position as a Vector object size (tuple): Size as (width, height) tuple center (tuple): Center point as (x, y) tuple center_x, center_y (float): Center point coordinates zoom (float): Zoom level for rendering grid_size (tuple): Grid dimensions (width, height) in tiles grid_x, grid_y (int): Grid dimensions texture (Texture): Tile texture atlas fill_color (Color): Background color entities (EntityCollection): Collection of entities in the grid perspective (int): Entity perspective index click (callable): Click event handler visible (bool): Visibility state opacity (float): Opacity value z_index (int): Rendering order name (str): Element name
at(...)compute_astar_path(x1: int, y1: int, x2: int, y2: int, diagonal_cost: float = 1.41) -> List[Tuple[int, int]]Compute A* path between two points.
Returns: List of (x, y) tuples representing the path, empty list if no path exists Alternative A* implementation. Prefer find_path() for consistency.
compute_dijkstra(root_x: int, root_y: int, diagonal_cost: float = 1.41) -> NoneCompute Dijkstra map from root position.
compute_fov(x: int, y: int, radius: int = 0, light_walls: bool = True, algorithm: int = FOV_BASIC) -> List[Tuple[int, int, bool, bool]]Compute field of view from a position and return visible cells.
Returns: List of tuples (x, y, visible, discovered) for all visible cells: - x, y: Grid coordinates - visible: True (all returned cells are visible) - discovered: True (FOV implies discovery) Also updates the internal FOV state for use with is_in_fov().
find_path(x1: int, y1: int, x2: int, y2: int, diagonal_cost: float = 1.41) -> List[Tuple[int, int]]Find A* path between two points.
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() -> tupleGet 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_dijkstra_distance(x: int, y: int) -> Optional[float]Get distance from Dijkstra root to position.
Returns: Distance as float, or None if position is unreachable or invalid Must call compute_dijkstra() first.
get_dijkstra_path(x: int, y: int) -> List[Tuple[int, int]]Get path from position to Dijkstra root.
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) -> boolCheck if a cell is in the field of view.
Returns: True if the cell is visible, False otherwise Must call compute_fov() first to calculate visibility.
move(dx: float, dy: float) -> NoneMove the element by a relative offset. Note:
resize(width: float, height: float) -> NoneResize the element to new dimensions. Note:
UIGridPoint object
UIGridPointState object
Base class for object-oriented scenes
activate() -> NoneMake this the active scene. Note:
Returns: None Deactivates the current scene and activates this one. Scene transitions and lifecycle callbacks are triggered.
get_ui() -> UICollectionGet the UI element collection for this scene. Note:
Returns: UICollection: Collection of UI elements (Frames, Captions, Sprites, Grids) in this scene Use to add, remove, or iterate over UI elements. Changes are reflected immediately.
register_keyboard(callback: callable) -> NoneRegister a keyboard event handler function. Note:
Returns: None Alternative to overriding on_keypress() method. Handler is called for both key press and release events.
Inherits from: Drawable
Sprite(pos=None, texture=None, sprite_index=0, **kwargs) A sprite UI element that displays a texture or portion of a texture atlas. Args: pos (tuple, optional): Position as (x, y) tuple. Default: (0, 0) texture (Texture, optional): Texture object to display. Default: default texture sprite_index (int, optional): Index into texture atlas. Default: 0 Keyword Args: scale (float): Uniform scale factor. Default: 1.0 scale_x (float): Horizontal scale factor. Default: 1.0 scale_y (float): Vertical scale factor. Default: 1.0 click (callable): Click event handler. Default: None visible (bool): Visibility state. Default: True opacity (float): Opacity (0.0-1.0). Default: 1.0 z_index (int): Rendering order. Default: 0 name (str): Element name for finding. Default: None x (float): X position override. Default: 0 y (float): Y position override. Default: 0 Attributes: x, y (float): Position in pixels pos (Vector): Position as a Vector object texture (Texture): The texture being displayed sprite_index (int): Current sprite index in texture atlas scale (float): Uniform scale factor scale_x, scale_y (float): Individual scale factors click (callable): Click event handler visible (bool): Visibility state opacity (float): Opacity value z_index (int): Rendering order name (str): Element name w, h (float): Read-only computed size based on texture and scale
get_bounds() -> tupleGet 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.
move(dx: float, dy: float) -> NoneMove the element by a relative offset. Note:
resize(width: float, height: float) -> NoneResize the element to new dimensions. Note:
SFML Texture Object
Timer(name, callback, interval, once=False) Create a timer that calls a function at regular intervals. Args: name (str): Unique identifier for the timer callback (callable): Function to call - receives (timer, runtime) args interval (int): Time between calls in milliseconds once (bool): If True, timer stops after first call. Default: False Attributes: interval (int): Time between calls in milliseconds remaining (int): Time until next call in milliseconds (read-only) paused (bool): Whether timer is paused (read-only) active (bool): Whether timer is active and not paused (read-only) callback (callable): The callback function once (bool): Whether timer stops after firing once Methods: pause(): Pause the timer, preserving time remaining resume(): Resume a paused timer cancel(): Stop and remove the timer restart(): Reset timer to start from beginning Example: def on_timer(timer, runtime): print(f'Timer {timer} fired at {runtime}ms') if runtime > 5000: timer.cancel() timer = mcrfpy.Timer('my_timer', on_timer, 1000) timer.pause() # Pause timer timer.resume() # Resume timer timer.once = True # Make it one-shot
cancel() -> NoneCancel the timer and remove it from the timer system. Note:
Returns: None The timer will no longer fire and cannot be restarted. The callback will not be called again.
pause() -> NonePause the timer, preserving the time remaining until next trigger. Note:
Returns: None The timer can be resumed later with resume(). Time spent paused does not count toward the interval.
restart() -> NoneRestart the timer from the beginning. Note:
Returns: None Resets the timer to fire after a full interval from now, regardless of remaining time.
resume() -> NoneResume a paused timer from where it left off. Note:
Returns: None Has no effect if the timer is not paused. Timer will fire after the remaining time elapses.
Iterable, indexable collection of UI objects
append(...)count(...)extend(...)index(...)remove(...)Iterator for a collection of UI objects
Iterator for a collection of UI objects
SFML Vector Object
angle() -> floatGet the angle of this vector in radians.
Returns: float: Angle in radians from positive x-axis
copy() -> VectorCreate a copy of this vector.
Returns: Vector: New Vector object with same x and y values
distance_to(other: Vector) -> floatCalculate the distance to another vector.
Returns: float: Distance between the two vectors
dot(other: Vector) -> floatCalculate the dot product with another vector.
Returns: float: Dot product of the two vectors
magnitude() -> floatCalculate the length/magnitude of this vector.
Returns: float: The magnitude of the vector
magnitude_squared() -> floatCalculate the squared magnitude of this vector. Note:
Returns: float: The squared magnitude (faster than magnitude()) Use this for comparisons to avoid expensive square root calculation.
normalize() -> VectorReturn a unit vector in the same direction. Note:
Returns: Vector: New normalized vector with magnitude 1.0 For zero vectors (magnitude 0.0), returns a zero vector rather than raising an exception
Window singleton for accessing and modifying the game window properties
center() -> NoneCenter the window on the screen. Note:
Returns: None Only works in windowed mode. Has no effect when fullscreen or in headless mode.
get() -> WindowGet the Window singleton instance. Note:
Returns: Window: The global window object This is a class method. Call as Window.get(). There is only one window instance per application.
screenshot(filename: str = None) -> bytes | NoneTake a screenshot of the current window contents. Note:
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.
FOV_BASIC (int): 0FOV_DIAMOND (int): 1FOV_PERMISSIVE_0 (int): 3FOV_PERMISSIVE_1 (int): 4FOV_PERMISSIVE_2 (int): 5FOV_PERMISSIVE_3 (int): 6FOV_PERMISSIVE_4 (int): 7FOV_PERMISSIVE_5 (int): 8FOV_PERMISSIVE_6 (int): 9FOV_PERMISSIVE_7 (int): 10FOV_PERMISSIVE_8 (int): 11FOV_RESTRICTIVE (int): 12FOV_SHADOW (int): 2