Update old format scene/timer examples

This commit is contained in:
John McCardle 2026-01-05 11:42:22 -05:00
commit 84d73e6aef
2 changed files with 26 additions and 15 deletions

View file

@ -214,12 +214,12 @@ McRogueFace is a C++ game engine with Python scripting support, designed for cre
### Key Python API (`mcrfpy` module) ### Key Python API (`mcrfpy` module)
The C++ engine exposes these primary functions to Python: The C++ engine exposes these primary functions to Python:
- Scene Management: `createScene()`, `setScene()`, `sceneUI()` - Scene Management: `Scene("name")` object
- Entity Creation: `Entity()` with position and sprite properties - Entity Creation: `Entity()` with position and sprite properties
- Grid Management: `Grid()` for tilemap rendering - Grid Management: `Grid()` for tilemap rendering
- Input Handling: `keypressScene()` for keyboard events - Input Handling: `keypressScene()` for keyboard events
- Audio: `createSoundBuffer()`, `playSound()`, `setVolume()` - Audio: `createSoundBuffer()`, `playSound()`, `setVolume()`
- Timers: `setTimer()`, `delTimer()` for event scheduling - Timers: `Timer("name")` object for event scheduling
## Development Workflow ## Development Workflow
@ -374,7 +374,7 @@ cp my_test.py scripts/game.py
mv scripts/game.py.bak scripts/game.py mv scripts/game.py.bak scripts/game.py
# Option 3: For quick tests, create minimal game.py # Option 3: For quick tests, create minimal game.py
echo 'import mcrfpy; print("Test"); mcrfpy.createScene("test")' > scripts/game.py echo 'import mcrfpy; print("Test"); scene = mcrfpy.Scene("test"); scene.activate()' > scripts/game.py
``` ```
### Understanding Key Macros and Patterns ### Understanding Key Macros and Patterns
@ -474,11 +474,11 @@ def run_test(runtime):
print("PASS") print("PASS")
sys.exit(0) sys.exit(0)
mcrfpy.createScene("test") test_scene = mcrfpy.Scene("test")
ui = mcrfpy.sceneUI("test") ui = test_scene.children
ui.append(mcrfpy.Frame(pos=(50,50), size=(100,100))) ui.append(mcrfpy.Frame(pos=(50,50), size=(100,100)))
mcrfpy.setScene("test") mcrfpy.current_scene = test_scene
mcrfpy.setTimer("test", run_test, 100) timer = mcrfpy.Timer("test", run_test, 100)
``` ```
### Key Testing Principles ### Key Testing Principles
@ -490,9 +490,17 @@ mcrfpy.setTimer("test", run_test, 100)
### API Quick Reference (from tests) ### API Quick Reference (from tests)
```python ```python
# Scene: create and activate a scene, or create another scene
mcrfpy.current_scene = mcrfpy.Scene("test")
demo_scene = mcrfpy.Scene("demo")
# Animation: (property, target_value, duration, easing) # Animation: (property, target_value, duration, easing)
anim = mcrfpy.Animation("x", 500.0, 2.0, "easeInOut") # direct use of Animation object: deprecated
anim.start(frame) #anim = mcrfpy.Animation("x", 500.0, 2.0, "easeInOut")
#anim.start(frame)
# preferred: create animations directly against the targeted object; use Enum of easing functions
frame.animate("x", 500.0, 2.0, mcrfpy.Easing.EASE_IN_OUT)
# Caption: use keyword arguments to avoid positional conflicts # Caption: use keyword arguments to avoid positional conflicts
cap = mcrfpy.Caption(text="Hello", pos=(100, 100)) cap = mcrfpy.Caption(text="Hello", pos=(100, 100))
@ -500,11 +508,14 @@ cap = mcrfpy.Caption(text="Hello", pos=(100, 100))
# Grid center: uses pixel coordinates, not cell coordinates # Grid center: uses pixel coordinates, not cell coordinates
grid = mcrfpy.Grid(grid_size=(15, 10), pos=(50, 50), size=(400, 300)) grid = mcrfpy.Grid(grid_size=(15, 10), pos=(50, 50), size=(400, 300))
grid.center = (120, 80) # pixels: (cells * cell_size / 2) grid.center = (120, 80) # pixels: (cells * cell_size / 2)
# grid center defaults to the position that puts (0, 0) in the top left corner of the grid's visible area.
# set grid.center to focus on that position. To position the camera in tile coordinates, use grid.center_camera():
grid.center_camera((14.5, 8.5)) # offset of 0.5 tiles to point at the middle of the tile
# Keyboard handler: key names are "Num1", "Num2", "Escape", "Q", etc. # Keyboard handler: key names are "Num1", "Num2", "Escape", "Q", etc.
def on_key(key, state): def on_key(key, state):
if key == "Num1" and state == "start": if key == "Num1" and state == "start":
mcrfpy.setScene("demo_1") demo_scene.activate()
``` ```
## Development Best Practices ## Development Best Practices
@ -744,4 +755,4 @@ If documentation isn't appearing, verify:
--- ---
- Close issues automatically in gitea by adding to the commit message "closes #X", where X is the issue number. This associates the issue closure with the specific commit, so granular commits are preferred. You should only use the MCP tool to close issues directly when discovering that the issue is already complete; when committing changes, always such "closes" (or the opposite, "reopens") references to related issues. If on a feature branch, the issue will be referenced by the commit, and when merged to master, the issue will be actually closed (or reopened). - Close issues automatically in gitea by adding to the commit message "closes #X", where X is the issue number. This associates the issue closure with the specific commit, so granular commits are preferred. You should only use the MCP tool to close issues directly when discovering that the issue is already complete; when committing changes, always such "closes" (or the opposite, "reopens") references to related issues. If on a feature branch, the issue will be referenced by the commit, and when merged to master, the issue will be actually closed (or reopened).

View file

@ -78,7 +78,7 @@ cd McRogueFace
import mcrfpy import mcrfpy
# Create a new scene # Create a new scene
mcrfpy.createScene("intro") intro = mcrfpy.Scene("intro")
# Add a text caption # Add a text caption
caption = mcrfpy.Caption((50, 50), "Welcome to McRogueFace!") caption = mcrfpy.Caption((50, 50), "Welcome to McRogueFace!")
@ -86,10 +86,10 @@ caption.size = 48
caption.fill_color = (255, 255, 255) caption.fill_color = (255, 255, 255)
# Add to scene # Add to scene
mcrfpy.sceneUI("intro").append(caption) intro.children.append(caption)
# Switch to the scene # Switch to the scene
mcrfpy.setScene("intro") intro.activate()
``` ```
## Documentation ## Documentation
@ -107,7 +107,7 @@ Key wiki pages:
- **[Python Binding System](https://gamedev.ffwf.net/gitea/john/McRogueFace/wiki/Python-Binding-System)** - C++/Python integration - **[Python Binding System](https://gamedev.ffwf.net/gitea/john/McRogueFace/wiki/Python-Binding-System)** - C++/Python integration
- **[Performance and Profiling](https://gamedev.ffwf.net/gitea/john/McRogueFace/wiki/Performance-and-Profiling)** - Optimization tools - **[Performance and Profiling](https://gamedev.ffwf.net/gitea/john/McRogueFace/wiki/Performance-and-Profiling)** - Optimization tools
- **[Adding Python Bindings](https://gamedev.ffwf.net/gitea/john/McRogueFace/wiki/Adding-Python-Bindings)** - Step-by-step binding guide - **[Adding Python Bindings](https://gamedev.ffwf.net/gitea/john/McRogueFace/wiki/Adding-Python-Bindings)** - Step-by-step binding guide
- **[Issue Roadmap](https://gamedev.ffwf.net/gitea/john/McRogueFace/wiki/Issue-Roadmap)** - All 46 open issues organized by system - **[Issue Roadmap](https://gamedev.ffwf.net/gitea/john/McRogueFace/wiki/Issue-Roadmap)** - All open issues organized by system
### 📖 Development Guides ### 📖 Development Guides