PointClickEngine::Core::SceneManager
Inherits PointClickEngine::Core::ISceneManager < PointClickEngine::Core::GameConstants < Reference < Object
Manages all scene-related operations including loading, transitions, and caching
The SceneManager centralizes scene handling logic that was previously scattered throughout the Engine class. It provides a clean API for scene operations and handles caching, preloading, and transition effects.
Features
- Scene loading and caching
- Smooth scene transitions with callbacks
- Scene preloading for performance
- Error handling for missing scenes
- Scene validation and integrity checking
- Memory management for unused scenes
Usage
manager = SceneManager.new
manager.add_scene(scene)
manager.change_scene("main_menu")
Constructors
Instance methods
Add a scene to the manager
Validates the scene and adds it to the available scenes collection.
Does not make the scene active - use change_scene for that.
- scene : The scene instance to add
Returns a Result indicating success or failure
Add multiple scenes at once
Validates and adds multiple scenes to the manager. If any scene fails validation, none are added.
- scenes : Array of scene instances to add
Change to a different scene
Transitions from the current scene to the specified scene. Handles exit callbacks for the current scene, loads the new scene if needed, and executes enter callbacks for the new scene.
The force_reload parameter can be used to reload the scene from cache even if it's already loaded, useful for resetting scene state.
Callback Order
- Exit callbacks for current scene
- Transition callbacks
- Scene activation
- Enter callbacks for new scene
Performance
Scenes are cached after first load for faster subsequent transitions.
Use force_reload to bypass cache when scene state needs resetting.
- name : Name of the scene to activate
- force_reload : Whether to reload from disk even if cached
Returns a Result with the activated scene or an error
Change scene with a transition effect
Performs a scene change with a visual transition effect. The transition will play, changing the scene at the midpoint of the effect.
- name : Name of the scene to transition to
- transition_type : Type of transition effect (fade, dissolve, slide_left, etc.)
- duration : Duration of the transition in seconds
- player_position : Optional position to place the player in the new scene
Returns a Result with success or error
Get a scene by name
Returns the scene if found, or an error if not found.
- name : Name of the scene to retrieve
Get a registered action sequence
- name : Name of the sequence to retrieve
Check if a sequence exists
- name : Name of the sequence to check
Set maximum cache size
- size : Maximum number of scenes to keep cached
Add a callback to be executed when entering a scene
- name : Name of the scene
- &block : Callback to execute on enter
Add a callback to be executed when exiting a scene
- name : Name of the scene
- &block : Callback to execute on exit
Add a callback to be executed during scene transition
- name : Name of the scene
- &block : Callback to execute during transition
Preload a scene without activating it
Loads a scene into the cache for faster switching later. Useful for preloading scenes during loading screens or idle time.
- name : Name of the scene to preload
Returns the preloaded scene or an error
Register an action sequence (for global sequences)
- name : Name of the sequence
- runner : The ActionRunner instance
Reload a scene from its definition
Forces a scene to reload, clearing any cached state. Useful for implementing "restart level" functionality.
- name : Name of the scene to reload
Remove a scene from the manager
Removes a scene from the available scenes. Cannot remove the currently active scene.
- name : Name of the scene to remove