Templates
Blank Spawnable Entity
TypeScript
import type {
PreviousArgs,
RenderTime,
SpawnableContext,
Time,
} from '@dreamlab.gg/core'
import { SpawnableEntity } from '@dreamlab.gg/core'
import type { Bounds, Vector } from '@dreamlab.gg/core/math'
import { z } from '@dreamlab.gg/core/sdk'
type Args = typeof ArgsSchema
const ArgsSchema = z.object({
// ... define args
})
export class ExampleEntity extends SpawnableEntity<Args> {
public constructor(ctx: SpawnableContext<Args>) {
super(ctx)
// initialize entity resources
}
public teardown(): void {
// free any used resources (eg: graphics primitives)
}
public bounds(): Bounds | undefined {
// return the bounding box size for this entity
// used in the dreamlab editor
// return undefined to signify this entity has no physical dimensions
// TODO: implement this correctly
return undefined
}
public isPointInside(point: Vector): boolean {
// test to check if a point is inside the entities hitbox
// used for click handling and editor selection
// TODO: implement this correctly
return false
}
public override onArgsUpdate(
path: string,
previousArgs: PreviousArgs<Args>,
): void {
// ... respond to args changing
}
public override onResize({ width, height }: Bounds): void {
// ... respond to width / height changing
}
public override onClick(position: Vector): void {
// ... click handler
}
public override onPhysicsStep(time: Time): void {
// ...
}
public override onRenderFrame(time: RenderTime): void {
// ...
}
}