Something went wrong. Try again.
Experimental canvas 2D engine for tile-based sidescroller/sandbox games, created strictly for educational purposes.
entity-component-system game-engine canvas-2d
Something went wrong. Try again.
123456789101112131415161718192021222324252627import { Entity, System, type Cosmic } from "@cosmic/core";import { Transform, Renderable } from "@cosmic/kit/components";
export class RenderingSystem extends System { public requiredComponents = new Set([Transform.name, Renderable.name]); private context: CanvasRenderingContext2D;
constructor(engine: Cosmic) { super(); this.context = engine.getContext(); }
public update(entities: Entity[]): void { this.context.clearRect(0, 0, 9999, 9999);
entities.forEach((entity) => { const transform = entity.getComponent(Transform)!;
this.context.strokeStyle = "#bf1d70"; if (transform.isCollidingWithEntity) this.context.strokeStyle = "#d6a5b0"; if (transform.isCollidingWithCanvasBoundaries) this.context.strokeStyle = "purple";
this.context.strokeRect(transform.x, transform.y, transform.width, transform.height); }); }}