UNPKG

2d-physics-engine

Version:

A lightweight, flexible 2D physics engine with ECS architecture, built with TypeScript

48 lines 1.3 kB
export class Scene { constructor() { Object.defineProperty(this, "entities", { enumerable: true, configurable: true, writable: true, value: new Set() }); Object.defineProperty(this, "entityCache", { enumerable: true, configurable: true, writable: true, value: null }); } addEntity(entity) { this.entities.add(entity); this.entityCache = null; // Invalidate cache } removeEntity(entity) { this.entities.delete(entity); this.entityCache = null; // Invalidate cache } getEntities() { // Cache entities array to avoid recreating it every frame if (!this.entityCache) { this.entityCache = Array.from(this.entities); } return this.entityCache; } update(deltaTime) { for (const entity of this.entities) { entity.update(deltaTime); } } onLoad() { // Initialize scene resources } onUnload() { // Cleanup scene resources for (const entity of this.entities) { entity.destroy(); } this.entities.clear(); this.entityCache = null; } } //# sourceMappingURL=Scene.js.map