Generated on 2025-07-10 01:04:50
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.
start(target)Start the animation on a target UI element.
get_current_value()Get the current interpolated value of the animation.
Caption(text='', x=0, y=0, font=None, fill_color=None, outline_color=None, outline=0, click=None) A text display UI element with customizable font and styling. Args: text (str): The text content to display. Default: '' x (float): X position in pixels. Default: 0 y (float): Y position in pixels. Default: 0 font (Font): Font object for text rendering. Default: engine default font 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 click (callable): Click event handler. Default: None Attributes: text (str): The displayed text content x, y (float): Position in pixels font (Font): Font used for rendering fill_color, outline_color (Color): Text appearance outline (float): Outline thickness click (callable): Click event handler visible (bool): Visibility state z_index (int): Rendering order w, h (float): Read-only computed size based on text and font
get_bounds()Get the bounding rectangle of this drawable element.
move(dx, dy)Move the element by a relative offset.
resize(width, height)Resize the element to new dimensions.
SFML Color Object
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
to_hex()Convert this Color to a hexadecimal string.
hex_str = color.to_hex() # Returns "#FF0000"
Base class for all drawable UI elements
get_bounds()Get the bounding rectangle of this drawable element.
move(dx, dy)Move the element by a relative offset.
resize(width, height)Resize the element to new dimensions.
UIEntity objects
move(dx, dy)Move the element by a relative offset.
resize(width, height)Resize the element to new dimensions.
index()Get the index of this entity in its parent grid's entity list.
at(x, y)Check if this entity is at the specified grid coordinates.
get_bounds()Get the bounding rectangle of this drawable element.
die()Remove this entity from its parent grid.
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.
index(entity)Find the index of the first occurrence of an entity.
extend(iterable)Add all entities from an iterable to the collection.
append(entity)Add an entity to the end of the collection.
SFML Font Object
Frame(x=0, y=0, w=0, h=0, fill_color=None, outline_color=None, outline=0, click=None, children=None) A rectangular frame UI element that can contain other drawable elements. Args: x (float): X position in pixels. Default: 0 y (float): Y position in pixels. Default: 0 w (float): Width in pixels. Default: 0 h (float): Height in pixels. Default: 0 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 Attributes: x, y (float): Position in pixels w, h (float): Size in pixels 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 z_index (int): Rendering order clip_children (bool): Whether to clip children to frame bounds
get_bounds()Get the bounding rectangle of this drawable element.
move(dx, dy)Move the element by a relative offset.
resize(width, height)Resize the element to new dimensions.
Grid(x=0, y=0, grid_size=(20, 20), texture=None, tile_width=16, tile_height=16, scale=1.0, click=None) A grid-based tilemap UI element for rendering tile-based levels and game worlds. Args: x (float): X position in pixels. Default: 0 y (float): Y position in pixels. Default: 0 grid_size (tuple): Grid dimensions as (width, height) in tiles. Default: (20, 20) texture (Texture): Texture atlas containing tile sprites. Default: None tile_width (int): Width of each tile in pixels. Default: 16 tile_height (int): Height of each tile in pixels. Default: 16 scale (float): Grid scaling factor. Default: 1.0 click (callable): Click event handler. Default: None Attributes: x, y (float): Position in pixels grid_size (tuple): Grid dimensions (width, height) in tiles tile_width, tile_height (int): Tile dimensions in pixels texture (Texture): Tile texture atlas scale (float): Scale multiplier points (list): 2D array of GridPoint objects for tile data entities (list): Collection of Entity objects in the grid background_color (Color): Grid background color click (callable): Click event handler visible (bool): Visibility state z_index (int): Rendering order
move(dx, dy)Move the element by a relative offset.
resize(width, height)Resize the element to new dimensions.
at(x, y)Get the GridPoint at the specified grid coordinates.
get_bounds()Get the bounding rectangle of this drawable element.
UIGridPoint object
UIGridPointState object
Base class for object-oriented scenes
keypress(handler)Register a keyboard handler function for this scene.
get_ui()Get the UI element collection 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(x=0, y=0, texture=None, sprite_index=0, scale=1.0, click=None) A sprite UI element that displays a texture or portion of a texture atlas. Args: x (float): X position in pixels. Default: 0 y (float): Y position in pixels. Default: 0 texture (Texture): Texture object to display. Default: None sprite_index (int): Index into texture atlas (if applicable). Default: 0 scale (float): Sprite scaling factor. Default: 1.0 click (callable): Click event handler. Default: None Attributes: x, y (float): Position in pixels texture (Texture): The texture being displayed sprite_index (int): Current sprite index in texture atlas scale (float): Scale multiplier click (callable): Click event handler visible (bool): Visibility state z_index (int): Rendering order w, h (float): Read-only computed size based on texture and scale
get_bounds()Get the bounding rectangle of this drawable element.
move(dx, dy)Move the element by a relative offset.
resize(width, height)Resize the element to new dimensions.
SFML Texture Object
Timer object for scheduled callbacks
resume()Resume a paused timer.
restart()Restart the timer from the beginning.
pause()Pause the timer, stopping its callback execution.
cancel()Cancel the timer and remove it from the system.
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.
index(drawable)Find the index of the first occurrence of a drawable.
extend(iterable)Add all drawables from an iterable to the collection.
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
copy()Create a copy of this vector.
angle()Get the angle of this vector in radians.
dot(other)Calculate the dot product with another vector.
magnitude()Calculate the length/magnitude of this vector.
length = vector.magnitude()
normalize()Return a unit vector in the same direction.
magnitude_squared()Calculate the squared magnitude of this vector.
distance_to(other)Calculate the distance to 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