The engine allows switching between game scenes dynamically from scripts. This is useful for moving from one level to another, returning to the main menu, or reloading the current scene.
| Function | Description |
|---|---|
LoadSceneByName(sceneName) |
Loads a new scene from the project, completely replacing the current one.
Parameters:
LoadSceneByName("Level2");
|
ReloadScene() |
Restarts the current scene without changing its name.
Commonly used to restart levels or retry after a "Game Over".
Example: ReloadScene();
|
GetSceneName() |
Returns the name of the scene currently loaded by the engine.
Returns: string or null
Example: let scene = GetSceneName();
|
// "Play" button script
function Start(obj) {
onClickUp(obj, () => {
LoadSceneByName("Level1");
});
}
When clicking the button, the scene Level1 loads and the game continues
automatically from its starting point.
// Player or GameManager script
function OnLevelComplete(obj) {
console.log("Level completed:", GetSceneName());
LoadSceneByName("Level2");
}
// "Retry" button script
function Start(obj) {
onClickUp(obj, () => {
console.log("Restarting level...");
ReloadScene();
});
}
Start() and Update() functions run again in objects of the new scene.You can combine scene switching with saving progress, stats, or achievements. For example, save the game before switching:
function OnLevelComplete(obj) {
SavePlayerData({ level: 1, points: 1200 });
LoadSceneByName("Level2");
}
This ensures player data is saved right before moving to the next level.