Component
Base class for behavior attached to a GameObject. Override lifecycle and event hooks to implement scripts.
Module: atlas
Base class for behavior attached to a GameObject. Override lifecycle and event hooks to implement scripts.
Declaration
export abstract class Component { ... }Properties
parentId
parentId: number;Methods
init
Initialization hook for attached script behavior.
abstract init(): void;update
Per-frame update hook.
abstract update(deltaTime: number): void;beforePhysics
Hook called before physics simulation.
beforePhysics(): void;atAttach
Hook called when the component is attached to its parent.
atAttach(): void;onCollisionEnter
Called when contact with another object begins.
onCollisionEnter(other: GameObject): void;onCollisionStay
Called while contact with another object continues.
onCollisionStay(other: GameObject): void;onCollisionExit
Called when contact with another object ends.
onCollisionExit(other: GameObject): void;onSignalReceive
Declared signal callback. The current runtime dispatches the legacy spelling onSignalRecieve.
onSignalReceive(signal: string, sender: GameObject): void;onSignalEnd
Called when a signal from the sending object ends.
onSignalEnd(signal: string, sender: GameObject): void;onQueryReceive
Receives a physics query result and the object owning this component.
onQueryReceive(query: QueryResult, sender: GameObject): void;getParent
Returns the parent object.
getParent(): GameObject;getParent<T extends Component>(
type: new (...args: any[]) => T,
): T | null;getObject
Looks up a scene object by numeric ID or string name.
getObject(identifier: number | string): CoreObject;getScene
Returns the active scene.
getScene(): Scene;getWindow
Returns the active runtime window.
getWindow(): Window;Examples
import { Component } from "atlas";
import { Position3d } from "atlas/units";
class Mover extends Component {
init(): void {}
update(deltaTime: number): void {
this.getParent().move(new Position3d(deltaTime, 0, 0));
}
}