Engine.run and GameConfig03 / 12

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.

01
Game configurationThe project defines system, assets, scenes and di
02
Engine.runThe SDK prepares systems and the canvas
03
The boot sceneThe SDK opens the scene selected by the project
The project describes the game; the SDK performs the shared startup process.

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.

Sources ↗

Block Puzzle · main.ts↗Importing Engine from the SDK and starting it with the project configuration.Block Puzzle · game.config.ts↗Game settings, assets, dependencies and the initial boot scene.