Starting a game from code
Trace how the project configuration reaches the engine when Block Puzzle starts.
In game/src/main.ts, Engine is imported from the SDK and BlockPuzzleGameConfig from the game project. The imports and startup call are shown below; the original file’s page-load check is omitted:
import { Engine } from '@gamedevland/engine';
import { BlockPuzzleGameConfig } from './config/game.config';
void Engine.run('#app', BlockPuzzleGameConfig.config);
The first argument, '#app', points to the HTML container <div id="app"></div>: the engine adds its canvas there. The second argument is the game configuration. It defines system settings, assets, scenes and project dependencies.
Engine.run creates and prepares the engine using these settings, then opens the initial scene. In Block Puzzle, scenes.initial is 'boot', so the project’s loading scene opens first.
Game classes, assets and rules remain in the project. The SDK provides the mechanism for connecting and starting them. To run another game, pass a different configuration to the same Engine.run.