The stats overlay is automatically created when you instantiate a World in a browser environment.
However, to enable and show it, use the function setDebugging to true.
12345
import{World}from"archetype-ecs-lib";constworld=newWorld();world.setDebugging(true);// Overlay appears automatically in top-left corner
constworld=newWorld({statsOverlayOptions:{left:10,// X position in pixelstop:10,// Y position in pixelswidth:400,// Canvas widthheight:100,// Canvas heighttargetFrameMs:16.67,// Target frame time (60 FPS)slowFrameMs:20,// Threshold for "slow" framesmaxSamples:240// History length in frames}});
// Check stats for current countsconststats=world.stats();console.log(`Alive: ${stats.aliveEntities}, Rows: ${stats.rows}`);// Iterate to find entities with specific componentsfor(const{e,c1}ofworld.query(Position)){console.log(`Entity ${e.id} has Position:`,c1);}
The overlay shows "Pending commands: true/false". If commands aren't being applied:
1234567
// Commands are deferredworld.cmd().spawn();console.log(world.stats().pendingCommands);// true// After flushworld.flush();console.log(world.stats().pendingCommands);// false
conststats=world.stats();constratio=stats.archetypes/stats.aliveEntities;if(ratio>0.1){// More than 1 archetype per 10 entitiesconsole.warn("Possible archetype fragmentation");}