Behavior lifecycle: On enable, On disable and On destroy events (#42)
game-maker / suite (push) Successful in 7m29s
game-maker / suite (push) Successful in 7m29s
Order per instance: On start -> On enable -> On update ... -> On disable -> On destroy. On enable fires right after On start and whenever the behavior comes back on (itself and its parents); On disable in the frame it goes off, the instance stays frozen. On destroy fires when the entity leaves the world (Destroy node, child of a destroyed object) and when the world is torn down on stop/restart, preceded by On disable if still on. A new On start node added while playing still does not fire for a running instance (kept as is, documented in the wiki). Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
1 parent
f0673d1957
commit
6141d07d4f
8 files changed
+203
-8
No files matched your search
+6
-2
@@ -239,6 +239,7 @@ export interface WorldOptions {
|
||||
export interface StartedWorld {
|
||||
world: World;
|
||||
collisions: CollisionSystem | null;
|
||||
behaviors: BehaviorSystem | null;
|
||||
/** Feed keys with `input.press('a')`; `frame()` clears the edges the way the editor does. */
|
||||
input: Input;
|
||||
/** One tick plus the end-of-frame bookkeeping the editor's play loop performs. */
|
||||
@@ -258,11 +259,14 @@ export function startWorld(fixture: SceneFixture, options: WorldOptions = {}): S
|
||||
const animations = options.animations ? new AnimationSystem() : null;
|
||||
if (collisions) world.addSystem(collisions);
|
||||
if (animations) world.addSystem(animations);
|
||||
if (options.behaviors)
|
||||
world.addSystem(new BehaviorSystem(fixture.project, input, { collisions, animations }));
|
||||
const behaviors = options.behaviors
|
||||
? new BehaviorSystem(fixture.project, input, { collisions, animations })
|
||||
: null;
|
||||
if (behaviors) world.addSystem(behaviors);
|
||||
return {
|
||||
world,
|
||||
collisions,
|
||||
behaviors,
|
||||
input,
|
||||
frame(dt = 1 / 60) {
|
||||
world.tick(dt);
|
||||
|
||||
Reference in new issue
Block a user