simvx.editor.play_mode¶
Play Mode — Run/pause/stop lifecycle for in-editor game preview.
Manages scene serialization/restoration, camera switching, input routing, and per-frame process/physics updates during play mode. Works alongside EditorState which holds the scene tree and play flags.
Usage: play_mode = PlayMode(editor_state) play_mode.start() # F5 — serialize scene, begin processing play_mode.toggle_pause() # F7 — pause/resume processing play_mode.stop() # F6 — restore pre-play scene state
# Called each frame by the editor's main loop:
play_mode.update(dt)
Module Contents¶
Classes¶
Manages the run/pause/stop lifecycle for previewing games in the editor. |
API¶
- class simvx.editor.play_mode.PlayMode(state: simvx.editor.state.EditorState)¶
Manages the run/pause/stop lifecycle for previewing games in the editor.
Coordinates with EditorState for scene access and flag storage. The editor’s process loop should call
update(dt)every frame.Initialization
- start() None¶
Begin play mode (triggered by F5).
Serializes the current scene so it can be restored on stop, locates the game camera, and starts processing the scene tree.
- toggle_pause() None¶
Toggle pause during play mode (triggered by F7).
When paused, process/physics updates are skipped but the scene continues to render so the user can inspect the frozen state.
- stop() None¶
Stop play mode and restore the pre-play scene (triggered by F6).
Deserializes the saved snapshot back into the scene tree, clearing any runtime state that was created during play.
- update(dt: float) None¶
Per-frame update, called by the editor’s process loop.
When playing and not paused this drives the scene’s
processandphysics_processcallbacks. Metrics are always updated so the status bar can show elapsed time and frame count.Args: dt: Delta time in seconds since the last frame.
- should_route_input_to_game() bool¶
Return True when game input events should be forwarded to the scene.
Editor-global shortcuts (F5/F6/F7) are always processed by the editor regardless of this flag.
- get_active_camera() simvx.core.Camera3D | None¶
Return the camera that should drive the viewport.
During play mode the game’s own Camera3D is used. Outside of play mode the editor’s orbit camera is returned.
- find_game_camera¶
None
- get_border_color() tuple[float, float, float, float] | None¶
Return a viewport border colour indicating the current play state.
Green
(0.2, 0.8, 0.2, 1.0)— game is running.Orange
(1.0, 0.6, 0.0, 1.0)— game is paused.None— editor is in normal (stopped) mode.
- property elapsed_time: float¶
Seconds elapsed since play mode started.
- property frame_count: int¶
Number of frames processed since play mode started.
- property is_active: bool¶
Convenience: True when the game is playing (paused or not).