GameObjRaw
:Base interface of all game objects.
since
v2000.0
group
Game Obj
children
: GameObj[]Get all children game objects.
readonly
since
v3000.0
transform
: Mat23Calculated transform matrix of a game object.
since
v3000.0
paused
: booleanIf update the game obj (run "update" event or not).
since
v2000.0
target
?: RenderTargetThe canvas to draw this game object on
since
v3001.0
setParent
(p: GameObj, opt: SetParentOpt): voidSet the parent game obj with additional options.
since
v4000.0
add
(comps?: CompList): GameObjAdd a child.
param
comps- The components to add.
returns
The added game object.
since
v3000.0
readd
(obj: GameObj<T>): 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): voidRemove a child.
param
obj- The game object to remove.
since
v3000.0
removeAll
(tag: Tag): voidRemove all children with a certain tag.
param
tag- The tag to remove.
since
v3000.0
removeAll
(): voidRemove all children.
since
v3000.0
destroy
(): voidRemove this game obj from scene.
since
v2000.0
exists
(): booleanIf game obj is attached to the scene graph.
returns
true if attached, false otherwise.
since
v2000.0
isAncestorOf
(obj: GameObj): booleanCheck if is an ancestor (recursive parent) of another game object
returns
true if is ancestor, false otherwise.
since
v3000.0
get
(tag: Tag | Tag[], opts?: GetOpt): GameObj<T>[]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
update
(): voidUpdate this game object and all children game objects.
since
v3000.0
fixedUpdate
(): voidUpdate this game object and all children game objects.
since
v3001.0
draw
(): voidDraw this game object and all children game objects.
since
v3000.0
drawTree
(): voidinspect
(): GameObjInspectGather debug info of all comps.
since
v2000.0
drawInspect
: () => voidDraw debug info in inspect mode
since
v3000.0
collectAndTransform
(objects: GameObj<any>[]): voidThis method is called to transform and collect objects which should be drawn layered
use
(comp: Comp): voidAdd a component.
const obj = add([
sprite("bean"),
]);
// Add opacity
obj.use(opacity(0.5));
since
v2000.0
unuse
(comp: string): voidRemove 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"): booleanCheck 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
c
(id: string): Comp | nullGet state for a specific comp.
param
id- The component id.
since
v2000.0
tag
(tag: Tag | Tag[]): voidAdd 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[]): voidRemove 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"): booleanIf 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: GameObjEventNames | ( string & {}), action: (args: any) => void): KEventControllerRegister 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): voidTrigger an event.
param
event- The event name.
param
args- The arguments to pass to the event action.
since
v2000.0
clearEvents
: () => voidClear all events.
onAdd
(action: () => void): KEventControllerRegister an event that runs when the game obj is added to the scene.
returns
The event controller.
since
v2000.0
onUpdate
(action: () => void): KEventControllerRegister an event that runs every frame as long as the game obj exists.
returns
The event controller.
since
v2000.1
onFixedUpdate
(action: () => void): KEventControllerRegister an event that runs every frame as long as the game obj exists.
returns
The event controller.
since
v2000.1
onDraw
(action: () => void): KEventControllerRegister 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): KEventControllerRegister an event that runs when the game obj is destroyed.
returns
The event controller.
since
v2000.1
onUse
(action: (id: string) => void): KEventControllerRegister an event that runs when a component is used.
returns
The event controller.
since
v4000.0
onUnuse
(action: (id: string) => void): KEventControllerRegister an event that runs when a component is unused.
returns
The event controller.
since
v4000.0
onTag
(action: (tag: string) => void): KEventControllerRegister an event that runs when a tag is added.
returns
The event controller.
since
v4000.0
onUntag
(action: (tag: string) => void): KEventControllerRegister an event that runs when a tag is removed.
returns
The event controller.
since
v4000.0