diff --git a/fxgl-core/src/main/kotlin/com/almasb/fxgl/core/EngineService.kt b/fxgl-core/src/main/kotlin/com/almasb/fxgl/core/EngineService.kt index d73090e66..45315fae9 100644 --- a/fxgl-core/src/main/kotlin/com/almasb/fxgl/core/EngineService.kt +++ b/fxgl-core/src/main/kotlin/com/almasb/fxgl/core/EngineService.kt @@ -30,6 +30,12 @@ abstract class EngineService : Updatable, SerializableType { */ open fun onMainLoopStarting() { } + /** + * Called after initGameVars() is completed. + * This is called on a background thread. + */ + open fun onVarsInitialized(vars: PropertyMap) { } + /** * Called when initGame(), initPhysics(), initUI() all completed and * the game is ready to be played. diff --git a/fxgl/src/main/kotlin/com/almasb/fxgl/app/Engine.kt b/fxgl/src/main/kotlin/com/almasb/fxgl/app/Engine.kt index 0a8c00e4d..a136a5056 100644 --- a/fxgl/src/main/kotlin/com/almasb/fxgl/app/Engine.kt +++ b/fxgl/src/main/kotlin/com/almasb/fxgl/app/Engine.kt @@ -138,6 +138,10 @@ internal class Engine(val settings: ReadOnlyGameSettings) { services.forEach { it.onGameUpdate(tpf) } } + fun onVarsInitialized(vars: PropertyMap) { + services.forEach { it.onVarsInitialized(vars) } + } + fun onGameReady(vars: PropertyMap) { services.forEach { it.onGameReady(vars) } } diff --git a/fxgl/src/main/kotlin/com/almasb/fxgl/app/FXGLApplication.kt b/fxgl/src/main/kotlin/com/almasb/fxgl/app/FXGLApplication.kt index f937823e5..60d2f31bf 100644 --- a/fxgl/src/main/kotlin/com/almasb/fxgl/app/FXGLApplication.kt +++ b/fxgl/src/main/kotlin/com/almasb/fxgl/app/FXGLApplication.kt @@ -338,6 +338,8 @@ class FXGLApplication : Application() { FXGL.getWorldProperties().setValue(name, value) } + engine.onVarsInitialized(FXGL.getWorldProperties()) + app.initGame(); }