Generated on 2025-07-08 11:53:54
createScene(name: str) -> None
Create a new empty scene with the given name.
mcrfpy.createScene("game_over")
setScene(scene: str, transition: str = None, duration: float = 0.0) -> None
Switch to a different scene with optional transition effect.
mcrfpy.setScene("game", "fade", 0.5)
currentScene() -> str
Get the name of the currently active scene.
scene_name = mcrfpy.currentScene()
sceneUI(scene: str = None) -> UICollection
Get all UI elements for a scene.
ui_elements = mcrfpy.sceneUI("game")
keypressScene(handler: callable) -> None
Set 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) -> int
Load a sound effect from a file and return its buffer ID.
jump_sound = mcrfpy.createSoundBuffer("assets/jump.wav")
loadMusic(filename: str, loop: bool = True) -> None
Load and immediately play background music from a file.
mcrfpy.loadMusic("assets/background.ogg", True)
playSound(buffer_id: int) -> None
Play a sound effect using a previously loaded buffer.
mcrfpy.playSound(jump_sound)
getMusicVolume() -> int
Get the current music volume level.
current_volume = mcrfpy.getMusicVolume()
getSoundVolume() -> int
Get the current sound effects volume level.
current_volume = mcrfpy.getSoundVolume()
setMusicVolume(volume: int) -> None
Set the global music volume.
mcrfpy.setMusicVolume(50) # Set to 50% volume
setSoundVolume(volume: int) -> None
Set the global sound effects volume.
mcrfpy.setSoundVolume(75) # Set to 75% volume
find(name: str, scene: str = None) -> UIDrawable | None
Find the first UI element with the specified name.
button = mcrfpy.find("start_button")
findAll(pattern: str, scene: str = None) -> list
Find all UI elements matching a name pattern.
enemies = mcrfpy.findAll("enemy_*")
exit() -> None
Cleanly shut down the game engine and exit the application.
mcrfpy.exit()
getMetrics() -> dict
Get current performance metrics.
metrics = mcrfpy.getMetrics()
setTimer(name: str, handler: callable, interval: int) -> None
Create or update a recurring timer.
def update_score(runtime):
score += 1
mcrfpy.setTimer("score_update", update_score, 1000)
delTimer(name: str) -> None
Stop and remove a timer.
mcrfpy.delTimer("score_update")
setScale(multiplier: float) -> None
Scale the game window size.
mcrfpy.setScale(2.0) # Double the window size
Animation object for animating UI properties
get_current_value()
Get the current interpolated value of the animation.
update(delta_time)
Update the animation by the given time delta.
start(target)
Start the animation on a target UI element.
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.
resize(width, height)
Resize the element to new dimensions.
move(dx, dy)
Move the element by a relative offset.
SFML Color Object
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"
from_hex(hex_string)
Create a Color from a hexadecimal color string.
red = Color.from_hex("#FF0000")
Base class for all drawable UI elements
get_bounds()
Get the bounding rectangle of this drawable element.
resize(width, height)
Resize the element to new dimensions.
move(dx, dy)
Move the element by a relative offset.
UIEntity objects
get_bounds()
Get the bounding rectangle of this drawable element.
move(dx, dy)
Move the element by a relative offset.
at(x, y)
Check if this entity is at the specified grid coordinates.
resize(width, height)
Resize the element to new dimensions.
index()
Get the index of this entity in its parent grid's entity list.
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.
extend(iterable)
Add all entities from an iterable to the collection.
append(entity)
Add an entity to the end of the collection.
index(entity)
Find the index of the first occurrence of an entity.
count(entity)
Count the number of occurrences of an entity in 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.
resize(width, height)
Resize the element to new dimensions.
move(dx, dy)
Move the element by a relative offset.
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
get_bounds()
Get the bounding rectangle of this drawable element.
at(x, y)
Get the GridPoint at the specified grid coordinates.
resize(width, height)
Resize the element to new dimensions.
move(dx, dy)
Move the element by a relative offset.
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.
resize(width, height)
Resize the element to new dimensions.
move(dx, dy)
Move the element by a relative offset.
SFML Texture Object
Timer object for scheduled callbacks
resume()
Resume a paused timer.
pause()
Pause the timer, stopping its callback execution.
cancel()
Cancel the timer and remove it from the system.
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.
extend(iterable)
Add all drawables from an iterable to the collection.
append(drawable)
Add a drawable element to the end of the collection.
index(drawable)
Find the index of the first occurrence of a drawable.
count(drawable)
Count the number of occurrences of a drawable in the collection.
Iterator for a collection of UI objects
Iterator for a collection of UI objects
SFML Vector Object
magnitude()
Calculate the length/magnitude of this vector.
length = vector.magnitude()
distance_to(other)
Calculate the distance to another vector.
angle()
Get the angle of this vector in radians.
dot(other)
Calculate the dot product with another vector.
normalize()
Return a unit vector in the same direction.
magnitude_squared()
Calculate the squared magnitude of this vector.
copy()
Create a copy of this vector.
Window singleton for accessing and modifying the game window properties
screenshot(filename)
Take a screenshot and save it to a file.
center()
Center the window on the screen.
get()
Get the Window singleton instance.
The mcrfpy.automation
module provides testing and automation capabilities.
automation.click
Click at position
automation.doubleClick
Double click at position
automation.dragRel
Drag mouse relative to current position
automation.dragTo
Drag mouse to position
automation.hotkey
Press a hotkey combination (e.g., hotkey('ctrl', 'c'))
automation.keyDown
Press and hold a key
automation.keyUp
Release a key
automation.middleClick
Middle click at position
automation.mouseDown
Press mouse button
automation.mouseUp
Release mouse button
automation.moveRel
Move mouse relative to current position
automation.moveTo
Move mouse to absolute position
automation.onScreen
Check if coordinates are within screen bounds
automation.position
Get current mouse position as (x, y) tuple
automation.rightClick
Right click at position
automation.screenshot
Save a screenshot to the specified file
automation.scroll
Scroll wheel at position
automation.size
Get screen size as (width, height) tuple
automation.tripleClick
Triple click at position
automation.typewrite
Type text with optional interval between keystrokes