GameObjRaw:
Base interface of all game objects.
since
v2000.0
add<T>(comps?: CompList | GameObj): GameObj<T>
Add a child.
param
comps- The components to add.
returns
The added game object.
since
v3000.0
readd<T>(obj: GameObj): GameObj<T>
Remove and re-add the game obj, without triggering add / destroy events.
param
obj- The game object to re-add.
returns
The re-added game object.
since
v3000.0
remove(obj: GameObj): void
Remove a child.
param
obj- The game object to remove.
since
v3000.0
removeAll(tag: Tag): void
Remove all children with a certain tag.
param
tag- The tag to remove.
since
v3000.0
removeAll(): void
Remove all children.
since
v3000.0
get(tag: Tag | Tag[], opts?: GetOpt): GameObj[]
Get a list of all game objs with certain tag.
param
tag- The tag to get.
since
v3000.0
query(opt: QueryOpt): GameObj[]
Get a list of all game objs with certain properties.
param
opt- The properties to get.
since
v3001.0
children: GameObj[]
readonly
Get all children game objects.
since
v3000.0
tags: string[]
readonly
Get the tags of a game object. For update it, use `tag()` and `untag()`.
since
v3001.0
fixedUpdate(): void
Update this game object and all children game objects.
since
v3001.0
update(): void
Update this game object and all children game objects.
since
v3000.0
draw(): void
Draw this game object and all children game objects.
since
v3000.0
drawInspect(): void
Draw debug info in inspect mode
since
v3000.0
clearEvents(): void
use(comp: Comp | Tag): void
Add a component.
const obj = add([ sprite("bean"), ]); // Add opacity obj.use(opacity(0.5));
since
v2000.0
unuse(comp: Tag): void
Remove a component with its id (the component name)
param
comp- The component id to remove. It means the name, if sprite, then it's "sprite".
// Remove sprite component obj.unuse("sprite");
since
v2000.0
has(compId: string | string[], op?: and | or): boolean
Check if game object has a certain component.
param
compId- The component id(s) to check.
param
op- The operator to use when searching for multiple components. Default is "and".
// Check if game object has sprite component if(obj.has("sprite")) { debug.log("has sprite component"); } // Check if game object has tags obj.has(["tag1", "tag2"]); // AND, it has both tags obj.has(["tag1", "tag2"], "or"); // OR, it has either tag1 or tag2
returns
true if has the component(s), false otherwise.
since
v3001.0.5
experimental
This feature is in experimental phase, it will be fully released in v3001.1.0
tag(tag: Tag | Tag[]): void
Add a tag(s) to the game obj.
param
tag- The tag(s) to add.
// add enemy tag obj.tag("enemy"); // add multiple tags obj.tag(["enemy", "boss"]);
since
v3001.0.5
experimental
This feature is in experimental phase, it will be fully released in v3001.1.0
untag(tag: Tag | Tag[]): void
Remove a tag(s) from the game obj.
param
tag- The tag(s) to remove.
// remove enemy tag obj.untag("enemy"); // remove multiple tags obj.untag(["enemy", "boss"]);
since
v3001.0.5
experimental
This feature is in experimental phase, it will be fully released in v3001.1.0
is(tag: Tag | Tag[], op?: and | or): boolean
If there's certain tag(s) on the game obj.
param
tag- The tag(s) for checking.
param
op- The operator to use when searching for multiple tags. Default is "and".
since
v3001.0.5
experimental
This feature is in experimental phase, it will be fully released in v3001.1.0
on(event: string, action: (args: any)=>void): KEventController
Register an event.
param
event- The event name.
param
action- The action to run when event is triggered.
returns
The event controller.
since
v2000.0
trigger(event: string, args: any): void
Trigger an event.
param
event- The event name.
parm
args - The arguments to pass to the event action.
since
v2000.0
destroy(): void
Remove the game obj from scene.
since
v2000.0
c(id: string): Comp | null
Get state for a specific comp.
param
id- The component id.
since
v2000.0
inspect(): GameObjInspect
Gather debug info of all comps.
since
v2000.0
onAdd(action: ()=>void): KEventController
Register an event that runs when the game obj is added to the scene.
returns
The event controller.
since
v2000.0
onUpdate(action: ()=>void): KEventController
Register an event that runs every frame as long as the game obj exists.
returns
The event controller.
since
v2000.1
onDraw(action: ()=>void): KEventController
Register an event that runs every frame as long as the game obj exists (this is the same as `onUpdate()`, but all draw events are run after all update events).
returns
The event controller.
since
v2000.1
onDestroy(action: ()=>void): KEventController
Register an event that runs when the game obj is destroyed.
returns
The event controller.
since
v2000.1
onUse(action: (id: string)=>void): KEventController
Register an event that runs when a component is used.
returns
The event controller.
since
v3001.0
onUnuse(action: (id: string)=>void): KEventController
Register an event that runs when a component is unused.
returns
The event controller.
since
v3001.0
exists(): boolean
If game obj is attached to the scene graph.
returns
true if attached, false otherwise.
since
v2000.0
isAncestorOf(obj: GameObj): boolean
Check if is an ancestor (recursive parent) of another game object
returns
true if is ancestor, false otherwise.
since
v3000.0
transform: Mat4
Calculated transform matrix of a game object.
since
v3000.0
paused: boolean
If update the game obj (run "update" event or not).
since
v2000.0
id: GameObjID | null
A unique number ID for each game object.
since
v2000.0
canvas: FrameBuffer | null
The canvas to draw this game object on
since
v3001.0