Base interface of all game objects.
sincev2000.0
groupGame Obj
add<T>(comps?: CompList): GameObj
Add a child.
paramcomps- The components to add.
returnsThe added game object.
sincev3000.0
readd<T>(obj: GameObj): GameObj<T>
Remove and re-add the game obj, without triggering add / destroy events.
paramobj- The game object to re-add.
returnsThe re-added game object.
sincev3000.0
remove(obj: GameObj): void
Remove a child.
paramobj- The game object to remove.
sincev3000.0
Remove all children with a certain tag.
paramtag- The tag to remove.
sincev3000.0
Remove all children.
sincev3000.0
get(tag: Tag | Tag[], opts?: GetOpt): GameObj[]
Get a list of all game objs with certain tag.
paramtag- The tag to get.
sincev3000.0
query(opt: QueryOpt): GameObj[]
Get a list of all game objs with certain properties.
paramopt- The properties to get.
sincev3001.0
readonlyGet all children game objects.
sincev3000.0
tags: string[]
readonlyGet the tags of a game object. For update it, use `tag()` and `untag()`.
sincev3001.0
Update this game object and all children game objects.
sincev3001.0
Update this game object and all children game objects.
sincev3000.0
Draw this game object and all children game objects.
sincev3000.0
Draw debug info in inspect mode
sincev3000.0
use(comp: Comp | Tag): void
Add a component.
const obj = add([
sprite("bean"),
]);
// Add opacity
obj.use(opacity(0.5));
sincev2000.0
unuse(comp: Tag): void
Remove a component with its id (the component name)
paramcomp- The component id to remove. It means the name, if sprite, then it's "sprite".
// Remove sprite component
obj.unuse("sprite");
sincev2000.0
has(compId: string | string[], op?: "and" | "or"): boolean
Check if game object has a certain component.
paramcompId- The component id(s) to check.
paramop- 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
returnstrue if has the component(s), false otherwise.
sincev3001.0.5
experimentalThis feature is in experimental phase, it will be fully released in v4000.0
tag(tag: Tag | Tag[]): void
Add a tag(s) to the game obj.
paramtag- The tag(s) to add.
// add enemy tag
obj.tag("enemy");
// add multiple tags
obj.tag(["enemy", "boss"]);
sincev3001.0.5
experimentalThis feature is in experimental phase, it will be fully released in v4000.0
untag(tag: Tag | Tag[]): void
Remove a tag(s) from the game obj.
paramtag- The tag(s) to remove.
// remove enemy tag
obj.untag("enemy");
// remove multiple tags
obj.untag(["enemy", "boss"]);
sincev3001.0.5
experimentalThis feature is in experimental phase, it will be fully released in v4000.0
is(tag: Tag | Tag[], op?: "and" | "or"): boolean
If there's certain tag(s) on the game obj.
paramtag- The tag(s) for checking.
paramop- The operator to use when searching for multiple tags. Default is "and".
sincev3001.0.5
experimentalThis feature is in experimental phase, it will be fully released in v4000.0
on(event: GameObjEventNames | string & {}, action: (args: any)=>void): KEventController
Register an event.
paramevent- The event name.
paramaction- The action to run when event is triggered.
returnsThe event controller.
sincev2000.0
trigger(event: string, args: any): void
Trigger an event.
paramevent- The event name.
parmargs - The arguments to pass to the event action.
sincev2000.0
Remove the game obj from scene.
sincev2000.0
c(id: string): Comp | null
Get state for a specific comp.
paramid- The component id.
sincev2000.0
inspect(): GameObjInspect
Gather debug info of all comps.
sincev2000.0
onAdd(action: ()=>void): KEventController
Register an event that runs when the game obj is added to the scene.
returnsThe event controller.
sincev2000.0
onUpdate(action: ()=>void): KEventController
Register an event that runs every frame as long as the game obj exists.
returnsThe event controller.
sincev2000.1
onFixedUpdate(action: ()=>void): KEventController
Register an event that runs every frame as long as the game obj exists.
returnsThe event controller.
sincev2000.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).
returnsThe event controller.
sincev2000.1
onDestroy(action: ()=>void): KEventController
Register an event that runs when the game obj is destroyed.
returnsThe event controller.
sincev2000.1
onUse(action: (id: string)=>void): KEventController
Register an event that runs when a component is used.
returnsThe event controller.
sincev3001.0
onUnuse(action: (id: string)=>void): KEventController
Register an event that runs when a component is unused.
returnsThe event controller.
sincev3001.0
onTag(action: (tag: string)=>void): KEventController
Register an event that runs when a tag is added.
returnsThe event controller.
sincev3001.10
experimental
onUntag(action: (tag: string)=>void): KEventController
Register an event that runs when a tag is removed.
returnsThe event controller.
sincev3001.10
experimental
If game obj is attached to the scene graph.
returnstrue if attached, false otherwise.
sincev2000.0
Check if is an ancestor (recursive parent) of another game object
returnstrue if is ancestor, false otherwise.
sincev3000.0
Calculated transform matrix of a game object.
sincev3000.0
If draw the game obj (run "draw" event or not).
sincev2000.0
If update the game obj (run "update" event or not).
sincev2000.0
canvas: FrameBuffer | null
The canvas to draw this game object on
sincev3001.0
onKeyDown: KAPLAYCtx["onKeyDown"]
onKeyPress: KAPLAYCtx["onKeyPress"]
onKeyRelease: KAPLAYCtx["onKeyRelease"]
onCharInput: KAPLAYCtx["onCharInput"]
onMouseDown: KAPLAYCtx["onMouseDown"]
onMousePress: KAPLAYCtx["onMousePress"]
onMouseRelease: KAPLAYCtx["onMouseRelease"]
onMouseMove: KAPLAYCtx["onMouseMove"]
onTouchStart: KAPLAYCtx["onTouchStart"]
onTouchMove: KAPLAYCtx["onTouchMove"]
onTouchEnd: KAPLAYCtx["onTouchEnd"]
onScroll: KAPLAYCtx["onScroll"]
onGamepadStick: KAPLAYCtx["onGamepadStick"]
onButtonDown: KAPLAYCtx["onButtonDown"]
onButtonPress: KAPLAYCtx["onButtonPress"]