From 6297622997805278a008dab5e8b19923fe8f0fee Mon Sep 17 00:00:00 2001 From: Mike Date: Thu, 8 Feb 2024 16:29:47 -0800 Subject: [PATCH] update the example --- README.md | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 7b6c002..3ee2e23 100644 --- a/README.md +++ b/README.md @@ -85,23 +85,23 @@ function rendererSystem (world) { const RENDERABLE_FILTER = [ 'renderable' ] // data structure to store all entities that were added or removed last frame - const resultEntries = { + const result = { count: 0, entries: new Array(100) } const onUpdate = function (dt) { - // optional 3rd parameter, can be 'added' or 'removed'. provides the list of entities that were + // optional 3rd parameter, can be 'added' or 'removed'. populates the list of entities that were // added since the last ECS.cleanup(...) call - for (ECS.getEntities(world, RENDERABLE_FILTER, 'added', resultEntries)) { - // resultEntries will now be filled in with a reference to all entries added last frame - } - - for (ECS.getEntities(world, RENDERABLE_FILTER, 'removed', resultEntries)) { - // resultEntries will now be filled in with a reference to all entries removed last frame - } - + ECS.getEntities(world, RENDERABLE_FILTER, 'added', result) + for (let i=0; i < result.count; i++) + console.log('added new entity:', result.entries[i]) + + // result will be filled in with a reference to all entries removed last frame + ECS.getEntities(world, RENDERABLE_FILTER, 'removed', result) + for (let i=0; i < result.count; i++) + console.log('removed entity:', result.entries[i]) } return { onUpdate }