Skip to content

CameraEntity

Defined in: renderer/src/CameraEntity.ts:78

Camera entity. Spawn in a scene to enable camera-based layer transforms.

const cam = this.spawn(CameraEntity, {
follow: player.get(Transform),
smoothing: 0.15,
bounds: { minX: 0, minY: 0, maxX: 2000, maxY: 2000 },
});
// All camera operations are available directly on the entity:
cam.shake(8, 300);
cam.zoomTo(1.5, 1000);
cam.follow(otherTarget, { smoothing: 0.1 });
  • Entity

new CameraEntity(name?, tags?): CameraEntity

Defined in: core/dist/index.d.ts:212

string

Iterable<string, any, any>

CameraEntity

Entity.constructor

readonly id: number

Defined in: core/dist/index.d.ts:193

Unique auto-incrementing ID.

Entity.id


readonly optional key?: string

Defined in: core/dist/index.d.ts:204

Stable identity key, scene-scoped. Set at spawn-time when options.key is passed to scene.spawn / entity.spawnChild; undefined otherwise. Used with scene.findByKey and as a stable id in reactive stores (e.g. a createSet<string>() persisted under "world.opened").

Entity.key


readonly name: string

Defined in: core/dist/index.d.ts:195

Display name for debugging.

Entity.name


readonly tags: Set<string>

Defined in: core/dist/index.d.ts:197

Tags for group queries.

Entity.tags


static [TRAITS_KEY]: Set<symbol>

Defined in: core/dist/index.d.ts:191

Entity.[TRAITS_KEY]

get bounds(): CameraBounds | undefined

Defined in: renderer/src/CameraEntity.ts:152

CameraBounds | undefined

set bounds(value): void

Defined in: renderer/src/CameraEntity.ts:156

CameraBounds | undefined

void


get children(): ReadonlyMap<string, Entity>

Defined in: core/dist/index.d.ts:232

Named children as a read-only map. Empty map if no children.

ReadonlyMap<string, Entity>

Entity.children


get effectivePosition(): Vec2

Defined in: renderer/src/CameraEntity.ts:160

Vec2


get isDestroyed(): boolean

Defined in: core/dist/index.d.ts:228

True if destroy() has been called.

boolean

Entity.isDestroyed


get parent(): Entity | null

Defined in: core/dist/index.d.ts:230

The parent entity, or null if this is a root entity.

Entity | null

Entity.parent


get position(): Vec2

Defined in: renderer/src/CameraEntity.ts:128

Vec2

set position(value): void

Defined in: renderer/src/CameraEntity.ts:132

Vec2

void


get rotation(): number

Defined in: renderer/src/CameraEntity.ts:144

number

set rotation(value): void

Defined in: renderer/src/CameraEntity.ts:148

number

void


get scene(): Scene

Defined in: core/dist/index.d.ts:224

The scene this entity belongs to. Throws if the entity is not attached to a scene — which in practice only happens before scene.spawn / addChild wires it up, or after destroy() tears it down. Inside lifecycle methods (setup, component onAdd, update, etc.) this is always safe to access.

For the rare case where you genuinely need to inspect whether an entity has a scene (e.g. defensive code in systems iterating a query result), use tryScene instead.

Scene

Entity.scene


get tryScene(): Scene | null

Defined in: core/dist/index.d.ts:226

The scene this entity belongs to, or null if detached.

Scene | null

Entity.tryScene


get zoom(): number

Defined in: renderer/src/CameraEntity.ts:136

number

set zoom(value): void

Defined in: renderer/src/CameraEntity.ts:140

number

void

_performDestroy(): void

Defined in: core/dist/index.d.ts:287

Internal

Internal: perform actual destruction — remove all components and clear state. Called by Scene during endOfFrame flush.

void

Entity._performDestroy


_setKey(key): void

Defined in: core/dist/index.d.ts:317

Internal

Internal: assign the stable identity key. Called by Scene._registerKey during spawn. Throws if the entity already has a key — keys are immutable for an entity’s lifetime.

string

void

Entity._setKey


_setScene(scene, callbacks): void

Defined in: core/dist/index.d.ts:310

Internal

Internal: set the scene and callbacks. Called by Scene.spawn().

Scene | null

EntityCallbacks | null

void

Entity._setScene


add<C>(component): C

Defined in: core/dist/index.d.ts:264

Add a component instance. Returns the component for chaining.

C extends Component

C

C

Entity.add


addChild(name, child): void

Defined in: core/dist/index.d.ts:234

Add a named child entity. Auto-adds to parent’s scene if not already in one.

string

Entity

void

Entity.addChild


afterRestore(): void

Defined in: renderer/src/CameraEntity.ts:196

Called after components are restored during save/load. Rebuild non-serializable state here.

void

Entity.afterRestore


destroy(): void

Defined in: core/dist/index.d.ts:281

Mark for deferred destruction. Actual cleanup happens at end of frame.

void

Entity.destroy


emit(token): void

Defined in: core/dist/index.d.ts:276

Emit a typed event on this entity. Bubbles to the scene.

EventToken<void>

void

Entity.emit

emit<T>(token, data): void

Defined in: core/dist/index.d.ts:277

Emit a typed event on this entity. Bubbles to the scene.

T

EventToken<T>

T

void

Entity.emit


follow(target, options?): void

Defined in: renderer/src/CameraEntity.ts:168

Vec2Like

CameraFollowOptions

void


get<C>(cls): C

Defined in: core/dist/index.d.ts:266

Get a component by class. Throws if not found.

C extends Component

ComponentClass<C>

C

Entity.get


getAll(): Iterable<Component>

Defined in: core/dist/index.d.ts:279

Get all components as an iterable.

Iterable<Component>

Entity.getAll


getChild(name): Entity

Defined in: core/dist/index.d.ts:260

Get a child by name. Throws if not found.

string

Entity

Entity.getChild


has(cls): boolean

Defined in: core/dist/index.d.ts:270

Check if entity has a component of the given class.

ComponentClass

boolean

Entity.has


hasTrait<T>(token): this is CameraEntity & T

Defined in: core/dist/index.d.ts:299

Check if this entity’s class implements a given trait. Acts as a type guard.

T

TraitToken<T>

this is CameraEntity & T

Entity.hasTrait


on<T>(token, handler): () => void

Defined in: core/dist/index.d.ts:274

Subscribe to a typed event on this entity. Returns an unsubscribe function.

T

EventToken<T>

(data) => void

() => void

Entity.on


remove(cls): void

Defined in: core/dist/index.d.ts:272

Remove a component by class.

ComponentClass

void

Entity.remove


removeChild(name): Entity

Defined in: core/dist/index.d.ts:258

Remove a named child. Returns the detached entity.

string

Entity

Entity.removeChild


requireKey(): string

Defined in: core/dist/index.d.ts:305

Return the stable key, or throw if this entity was spawned without one. Use inside component setup() when the component depends on identity (e.g. reading from a createSet keyed by entity key).

string

Entity.requireKey


screenToWorld(screenX, screenY): Vec2

Defined in: renderer/src/CameraEntity.ts:188

number

number

Vec2


optional serialize(): unknown

Defined in: core/dist/index.d.ts:295

Return a JSON-serializable snapshot of this entity’s custom state. Used by the save system.

unknown

Entity.serialize


setup(params?): void

Defined in: renderer/src/CameraEntity.ts:81

Optional setup method. Called by scene.spawn(Class, params) after the entity is wired to its scene, so components can access services. Override in subclasses — do NOT use the constructor for component setup.

CameraEntityParams = {}

void

Entity.setup


shake(intensity, duration, options?): void

Defined in: renderer/src/CameraEntity.ts:176

number

number

CameraShakeOptions

void


spawnChild(name, options?): Entity

Defined in: core/dist/index.d.ts:250

Spawn a new entity in this entity’s scene and add it as a named child. Combines scene.spawn(...) + this.addChild(name, ...) in one call — the idiomatic way to compose entity trees (logical root + visual body

  • UI sibling + …).

Mirrors the overload shape of Scene.spawn: pass an Entity subclass (with optional setup params), a Blueprint, or omit for an anonymous base Entity.

this.spawnChild("body", EnemyBody, { color: 0xff6b6b });
this.spawnChild("hp", EnemyHealthBar);

string

SpawnOptions

Entity

Entity.spawnChild

spawnChild<E>(name, Class, options?): E

Defined in: core/dist/index.d.ts:251

Spawn a new entity in this entity’s scene and add it as a named child. Combines scene.spawn(...) + this.addChild(name, ...) in one call — the idiomatic way to compose entity trees (logical root + visual body

  • UI sibling + …).

Mirrors the overload shape of Scene.spawn: pass an Entity subclass (with optional setup params), a Blueprint, or omit for an anonymous base Entity.

this.spawnChild("body", EnemyBody, { color: 0xff6b6b });
this.spawnChild("hp", EnemyHealthBar);

E extends Entity

string

() => E

SpawnOptions

E

Entity.spawnChild

spawnChild<E, P>(name, Class, params, options?): E

Defined in: core/dist/index.d.ts:252

Spawn a new entity in this entity’s scene and add it as a named child. Combines scene.spawn(...) + this.addChild(name, ...) in one call — the idiomatic way to compose entity trees (logical root + visual body

  • UI sibling + …).

Mirrors the overload shape of Scene.spawn: pass an Entity subclass (with optional setup params), a Blueprint, or omit for an anonymous base Entity.

this.spawnChild("body", EnemyBody, { color: 0xff6b6b });
this.spawnChild("hp", EnemyHealthBar);

E extends Entity

P

string

() => E & object

P

SpawnOptions

E

Entity.spawnChild

spawnChild<P>(name, blueprint, params, options?): Entity

Defined in: core/dist/index.d.ts:255

Spawn a new entity in this entity’s scene and add it as a named child. Combines scene.spawn(...) + this.addChild(name, ...) in one call — the idiomatic way to compose entity trees (logical root + visual body

  • UI sibling + …).

Mirrors the overload shape of Scene.spawn: pass an Entity subclass (with optional setup params), a Blueprint, or omit for an anonymous base Entity.

this.spawnChild("body", EnemyBody, { color: 0xff6b6b });
this.spawnChild("hp", EnemyHealthBar);

P

string

Blueprint<P>

P

SpawnOptions

Entity

Entity.spawnChild

spawnChild(name, blueprint, options?): Entity

Defined in: core/dist/index.d.ts:256

Spawn a new entity in this entity’s scene and add it as a named child. Combines scene.spawn(...) + this.addChild(name, ...) in one call — the idiomatic way to compose entity trees (logical root + visual body

  • UI sibling + …).

Mirrors the overload shape of Scene.spawn: pass an Entity subclass (with optional setup params), a Blueprint, or omit for an anonymous base Entity.

this.spawnChild("body", EnemyBody, { color: 0xff6b6b });
this.spawnChild("hp", EnemyHealthBar);

string

Blueprint<void>

SpawnOptions

Entity

Entity.spawnChild


tryGet<C>(cls): C | undefined

Defined in: core/dist/index.d.ts:268

Get a component by class, or undefined if not found.

C extends Component

ComponentClass<C>

C | undefined

Entity.tryGet


tryGetChild(name): Entity | undefined

Defined in: core/dist/index.d.ts:262

Get a child by name, or undefined if not found.

string

Entity | undefined

Entity.tryGetChild


unfollow(): void

Defined in: renderer/src/CameraEntity.ts:172

void


worldToScreen(worldX, worldY): Vec2

Defined in: renderer/src/CameraEntity.ts:192

number

number

Vec2


zoomTo(target, duration, easing?): void

Defined in: renderer/src/CameraEntity.ts:184

number

number

EasingFunction

void