Generated on 2025-07-15 21:28:13
createScene(name: str) -> NoneCreate a new empty scene with the given name.
mcrfpy.createScene("game_over")
setScene(scene: str, transition: str = None, duration: float = 0.0) -> NoneSwitch to a different scene with optional transition effect.
mcrfpy.setScene("game", "fade", 0.5)
currentScene() -> strGet the name of the currently active scene.
scene_name = mcrfpy.currentScene()
sceneUI(scene: str = None) -> UICollectionGet all UI elements for a scene.
ui_elements = mcrfpy.sceneUI("game")
keypressScene(handler: callable) -> NoneSet the keyboard event handler for the current scene.
def on_key(key, pressed):
if key == "SPACE" and pressed:
player.jump()
mcrfpy.keypressScene(on_key)
createSoundBuffer(filename: str) -> intLoad a sound effect from a file and return its buffer ID.
jump_sound = mcrfpy.createSoundBuffer("assets/jump.wav")
loadMusic(filename: str, loop: bool = True) -> NoneLoad and immediately play background music from a file.
mcrfpy.loadMusic("assets/background.ogg", True)
playSound(buffer_id: int) -> NonePlay a sound effect using a previously loaded buffer.
mcrfpy.playSound(jump_sound)
getMusicVolume() -> intGet the current music volume level.
current_volume = mcrfpy.getMusicVolume()
getSoundVolume() -> intGet the current sound effects volume level.
current_volume = mcrfpy.getSoundVolume()
setMusicVolume(volume: int) -> NoneSet the global music volume.
mcrfpy.setMusicVolume(50) # Set to 50% volume
setSoundVolume(volume: int) -> NoneSet the global sound effects volume.
mcrfpy.setSoundVolume(75) # Set to 75% volume
find(name: str, scene: str = None) -> UIDrawable | NoneFind the first UI element with the specified name.
button = mcrfpy.find("start_button")
findAll(pattern: str, scene: str = None) -> listFind all UI elements matching a name pattern.
enemies = mcrfpy.findAll("enemy_*")
exit() -> NoneCleanly shut down the game engine and exit the application.
mcrfpy.exit()
getMetrics() -> dictGet current performance metrics.
metrics = mcrfpy.getMetrics()
setTimer(name: str, handler: callable, interval: int) -> NoneCreate or update a recurring timer.
def update_score(runtime):
score += 1
mcrfpy.setTimer("score_update", update_score, 1000)
delTimer(name: str) -> NoneStop and remove a timer.
mcrfpy.delTimer("score_update")
setScale(multiplier: float) -> NoneScale the game window size.
mcrfpy.setScale(2.0) # Double the window size
Animation object for animating UI properties
update(delta_time)Update the animation by the given time delta.
get_current_value()Get the current interpolated value of the animation.
start(target)Start the animation on a target UI element.
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
move(dx, dy)Move the element by a relative offset.
get_bounds()Get the bounding rectangle of this drawable element.
resize(width, height)Resize the element to new dimensions.
SFML Color Object
to_hex()Convert this Color to a hexadecimal string.
hex_str = color.to_hex() # Returns "#FF0000"
from_hex(hex_string)Create a Color from a hexadecimal color string.
red = Color.from_hex("#FF0000")
lerp(other, t)Linearly interpolate between this color and another.
mixed = red.lerp(blue, 0.5) # 50% between red and blue
Base class for all drawable UI elements
move(dx, dy)Move the element by a relative offset.
get_bounds()Get the bounding rectangle of this drawable element.
resize(width, height)Resize the element to new dimensions.
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
die()Remove this entity from its parent grid.
move(dx, dy)Move the element by a relative offset.
at(x, y)Check if this entity is at the specified grid coordinates.
get_bounds()Get the bounding rectangle of this drawable element.
resize(width, height)Resize the element to new dimensions.
index()Get the index of this entity in its parent grid's entity list.
Iterable, indexable collection of Entities
remove(entity)Remove the first occurrence of an entity from the collection.
count(entity)Count the number of occurrences of an entity in the collection.
extend(iterable)Add all entities from an iterable to the collection.
index(entity)Find the index of the first occurrence of an entity.
append(entity)Add an entity to the end of the collection.
SFML Font Object
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
move(dx, dy)Move the element by a relative offset.
get_bounds()Get the bounding rectangle of this drawable element.
resize(width, height)Resize the element to new dimensions.
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
move(dx, dy)Move the element by a relative offset.
at(x, y)Get the GridPoint at the specified grid coordinates.
get_bounds()Get the bounding rectangle of this drawable element.
resize(width, height)Resize the element to new dimensions.
UIGridPoint object
UIGridPointState object
Base class for object-oriented scenes
get_ui()Get the UI element collection for this scene.
keypress(handler)Register a keyboard handler function for this scene.
activate()Make this scene the active scene.
register_keyboard(callable)Register a keyboard event handler function for the scene.
def handle_keyboard(key, action):
print(f"Key '{key}' was {action}")
if key == "q" and action == "press":
# Handle quit
pass
scene.register_keyboard(handle_keyboard)
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
move(dx, dy)Move the element by a relative offset.
get_bounds()Get the bounding rectangle of this drawable element.
resize(width, height)Resize the element to new dimensions.
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()Cancel the timer and remove it from the system.
pause()Pause the timer, stopping its callback execution.
resume()Resume a paused timer.
restart()Restart the timer from the beginning.
Iterable, indexable collection of UI objects
remove(drawable)Remove the first occurrence of a drawable from the collection.
count(drawable)Count the number of occurrences of a drawable in the collection.
extend(iterable)Add all drawables from an iterable to the collection.
index(drawable)Find the index of the first occurrence of a drawable.
append(drawable)Add a drawable element to the end of the collection.
Iterator for a collection of UI objects
Iterator for a collection of UI objects
SFML Vector Object
magnitude_squared()Calculate the squared magnitude of this vector.
copy()Create a copy of this vector.
magnitude()Calculate the length/magnitude of this vector.
length = vector.magnitude()
angle()Get the angle of this vector in radians.
distance_to(other)Calculate the distance to another vector.
normalize()Return a unit vector in the same direction.
dot(other)Calculate the dot product with another vector.
Window singleton for accessing and modifying the game window properties
get()Get the Window singleton instance.
screenshot(filename)Take a screenshot and save it to a file.
center()Center the window on the screen.
The mcrfpy.automation module provides testing and automation capabilities.
automation.clickClick at position
automation.doubleClickDouble click at position
automation.dragRelDrag mouse relative to current position
automation.dragToDrag mouse to position
automation.hotkeyPress a hotkey combination (e.g., hotkey('ctrl', 'c'))
automation.keyDownPress and hold a key
automation.keyUpRelease a key
automation.middleClickMiddle click at position
automation.mouseDownPress mouse button
automation.mouseUpRelease mouse button
automation.moveRelMove mouse relative to current position
automation.moveToMove mouse to absolute position
automation.onScreenCheck if coordinates are within screen bounds
automation.positionGet current mouse position as (x, y) tuple
automation.rightClickRight click at position
automation.screenshotSave a screenshot to the specified file
automation.scrollScroll wheel at position
automation.sizeGet screen size as (width, height) tuple
automation.tripleClickTriple click at position
automation.typewriteType text with optional interval between keystrokes