Component
Base class for everything attached to a SceneObject.
| Type | Name | Interface Description |
|---|---|---|
| Variables | enabled: boolean | • Function: Gets whether the component is enabled. True if the component is enabled, false otherwise. |
| Functions | constructor() | |
| Functions | getSceneObject(): SceneObject | • Function: Gets the scene object this component is attached to. Returns The scene object this component is attached to. |
| Functions | isInheritedEnabled(): boolean | • Function: Checks if the component is inheritedEnabled. Returns True if the component is inherited and enabled, false otherwise. |
Examples
constructor()
let obj = new APJS.Component();
Use Case
Example 1 — Audio manager with BGM loop + multiple SFX channels — demonstrates the BGM+SFX pattern with separate Audio Player objects
@component()
export class MultiSfxManager extends APJS.BasicScriptComponent {
@serializeProperty
bgmPlayer!: APJS.SceneObject;
@serializeProperty
clickPlayer!: APJS.SceneObject;
@serializeProperty
successPlayer!: APJS.SceneObject;
@serializeProperty
failPlayer!: APJS.SceneObject;
private bgm!: APJS.AudioComponent;
private clickSfx!: APJS.AudioComponent;
private successSfx!: APJS.AudioComponent;
private failSfx!: APJS.AudioComponent;
private initialized = false;
onUpdate(dt: number): void {
if (!this.initialized && this.bgmPlayer) {
this.bgm = this.bgmPlayer.getComponent("AudioComponent") as APJS.AudioComponent;
this.clickSfx = this.clickPlayer.getComponent("AudioComponent") as APJS.AudioComponent;
this.successSfx = this.successPlayer.getComponent("AudioComponent") as APJS.AudioComponent;
this.failSfx = this.failPlayer.getComponent("AudioComponent") as APJS.AudioComponent;
if (!this.bgm || !this.clickSfx) return;
// Start BGM (playMode set to Infinity via DSL)
this.bgm.volume = 40;
this.bgm.play();
this.initialized = true;
}
}
playClick(): void {
this.clickSfx.stop();
this.clickSfx.loopCount = 1;
this.clickSfx.volume = 100;
this.clickSfx.play();
}
playSuccess(): void {
this.successSfx.stop();
this.successSfx.loopCount = 1;
this.successSfx.volume = 100;
this.successSfx.play();
}
playFail(): void {
this.failSfx.stop();
this.failSfx.loopCount = 1;
this.failSfx.volume = 100;
this.failSfx.play();
}
}
Example 2 — Use @serializeProperty to bind external scene objects, textures, and config values from the editor
@component()
export class SerializePropertyBinding extends APJS.BasicScriptComponent {
@serializeProperty
private targetObject: APJS.SceneObject;
@serializeProperty
private displayText: APJS.SceneObject;
@serializeProperty
private iconTexture: APJS.Texture;
@serializeProperty
private speed: number = 5;
@serializeProperty
private autoStart: boolean = true;
private textComponent: APJS.Text;
private imageComponent: APJS.Image;
onStart(): void {
// Get component references from serialized SceneObject bindings
this.textComponent = this.displayText.getComponent("Text") as APJS.Text;
this.imageComponent = this.targetObject.getComponent("Image") as APJS.Image;
if (this.imageComponent && this.iconTexture) {
this.imageComponent.texture = this.iconTexture;
}
if (this.textComponent) {
this.textComponent.text = "Ready";
}
}
}