Every element in this.dom, including this.root, is the real HTML element with some extra helpers added by the engine. Some node types add their own controls on top. In the editor's types this combination is called MammutElement (see Script Types).
Every element
| Member | Description |
|---|---|
hide() |
Hides the element |
show() |
Shows it again |
isHidden() |
Whether it's hidden |
hidden |
Hides or shows it by setting true or false |
toggleVisibility() |
Hides it if shown, shows it if hidden |
disableEvents() |
Stops it reacting to the mouse |
enableEvents() |
Lets it react to the mouse again |
getState() |
The node's current state |
setState() |
Switches to one of the node's states |
hide
element.hide(): void
Hides the element. It takes up no space and can't be clicked.
How it works
- It adds the
mm-hiddenclass, which setsdisplay: none. - A node with Visible unticked in the inspector starts hidden the same way, so
show()reveals it. - Hiding an element hides everything inside it.
Example
onStart() {
this.dom.tooltip.hide();
},
show
element.show(): void
Shows an element hidden with hide(), or one that started with Visible unticked.
Example
onHelpPressed() {
this.dom.tooltip.show();
},
isHidden
element.isHidden(): boolean
Returns true while the element is hidden by hide() or by Visible being unticked. It doesn't check whether a parent element is hidden.
Example
onHelpPressed() {
if (this.dom.tooltip.isHidden()) this.dom.tooltip.show();
},
hidden
element.hidden: boolean
Reading it is the same as isHidden(). Setting it to true hides the element and false shows it. The text "true" and "false" work too.
Example
onToggleChanged(checked: boolean) {
this.dom.advanced_options.hidden = !checked; // show the options while the box is ticked
},
toggleVisibility
element.toggleVisibility(): void
Hides the element if it's showing, and shows it if it's hidden.
Example
onMapPressed() {
this.dom.map_panel.toggleVisibility();
},
disableEvents
element.disableEvents(): void
Stops the element and everything inside it reacting to the mouse and touch: clicks, presses, hovering and movement.
How it works
- Hover styles stop showing while events are disabled.
- Keyboard input isn't affected. Use InputManager for keys.
Example
async onAnswerPressed() {
this.dom.answers.disableEvents(); // no double answers while the result plays
await this.dom.result.setState("reveal");
this.dom.answers.enableEvents();
},
enableEvents
element.enableEvents(): void
Lets the element react to the mouse and touch again after disableEvents().
getState
element.getState(): string | null
Returns the name of the state the node is in, from its States list (see States), or null if it isn't in one.
Example
onCardPressed() {
const next = this.dom.card.getState() === "flipped" ? "front" : "flipped";
this.dom.card.setState(next);
},
setState
element.setState(state: string, repeat = true): Promise<void>
Switches the node to one of the states in its States list, replacing the state it was in.
| Parameter | Type | Default | Description |
|---|---|---|---|
state |
string |
The state's name | |
repeat |
boolean |
true |
false does nothing if the node is already in this state, instead of replaying its animation |
Returns a promise that resolves when the state's animation finishes, or straight away if it has no animation.
How it works
- Calling it again with the same state replays the animation, unless
repeatisfalse. - Switching to another state before the animation finishes resolves the earlier promise straight away.
- Calling it with no state takes the node out of its current state, but also logs an error.
Example
async onWin() {
await this.dom.trophy.setState("bounce"); // waits for the bounce animation
this.dom.continue_button.show();
},
Animator nodes
Animator nodes (see Animator) add these controls. A clip is named by its key in the node's clip list.
| Member | Description |
|---|---|
play(clip?) |
Plays a clip, replacing the one playing. With no clip, plays the node's default clip |
pause() |
Freezes the clip where it is |
resume() |
Carries on after pause() |
stop() |
Stops the clip and returns the node to how it looked before |
restart(clip?) |
Plays a clip from the start. With no clip, restarts the one playing |
How it works
- Only one clip plays at a time.
- Trigger markers in a clip fire as it plays, and stop firing while it's paused.
play()andrestart()do nothing if there's no clip to play.
Example
onStart() {
this.dom.hero.play("idle");
},
async onJump() {
this.dom.hero.restart("jump"); // from the start, even if it was already jumping
await delay(600);
this.dom.hero.play("idle");
},
Particle nodes
Particle nodes (see Particles) add these controls.
| Member | Description |
|---|---|
start() |
Starts emitting particles |
stop() |
Stops emitting |
pause() |
Freezes the particles where they are |
resume() |
Carries on after pause() |
burst(count: number) |
Emits count particles at once |
Example
onCoinCollected() {
this.dom.sparkles.burst(30); // a one-off puff of 30 particles
},
Sprite Loop nodes
Sprite Loop nodes (see Sprite Loop) add these controls. Animations, skins, parts and variants can be named by their id, key or display name.
| Member | Description |
|---|---|
animations |
The ids of the package's animations |
currentAnimation |
The id of the animation shown now, or null |
play(animation?, options?) |
Plays an animation from the start |
pause() |
Freezes the animation |
resume() |
Carries on after pause() |
stop() |
Stops and goes back to the first frame |
setFrame(frame, emitEvents = true) |
Jumps to a frame |
setSkin(skin) |
Applies a skin |
setVariant(part, variant) |
Shows a variant on one part |
clearVariant(part) |
Removes a part's variant |
clearVariants() |
Removes every part's variant |
setTint(r, g, b) |
Multiplies every part's colour |
clearTint() |
Removes the tint |
getPartTransform(part, origin = "pivot") |
Where a part is right now |
onEvent(name, handler) |
Listens for a frame event |
offEvent(name, handler?) |
Stops listening |
play (Sprite Loop)
element.play(animation?: string, options?: { loop?: boolean; speed?: number }): Promise<void>
Plays an animation from its first frame. With no animation, plays the current one again, or the first in the package.
| Parameter | Type | Default | Description |
|---|---|---|---|
animation |
string |
The current animation | The animation's id, key or name |
options.loop |
boolean |
The node's Loop setting | true to loop, false to play once |
options.speed |
number |
The current speed | Playback speed, 1 is normal. It stays at this speed for later animations |
Returns a promise that resolves when a play-once animation reaches its end, or when it's replaced or stopped. A looping animation's promise resolves only when it's replaced or stopped.
Example
async onAttack() {
await this.dom.knight.play("attack", { loop: false }); // wait for the swing to finish
this.dom.knight.play("idle", { loop: true });
},
setVariant and setSkin
element.setSkin(skin: string): boolean
element.setVariant(part: string, variant: string): boolean
setSkin applies a skin's variants and part visibility. setVariant shows one variant on one part, on top of the skin. Pass "default" as the variant to go back to the skin's.
Returns false if the skin, part or variant doesn't exist.
Example
onOutfitChosen(outfit: string) {
if (!this.dom.alice.setSkin(outfit)) logWarning(`No skin called ${outfit}`);
this.dom.alice.setVariant("mouth", "smile");
},
onEvent
element.onEvent(name: string, handler: (event: SpriteLoopEvent) => void): () => void
Calls handler each time the animation reaches a frame with that event. Pass "*" to hear every event. The handler receives name, data, animation, frame and sourceFrame.
Returns a function that removes the handler.
How it works
- The handler isn't removed when the scene exits, but it goes away with the node.
offEvent(name)with no handler removes every handler for that name.
Example
onStart() {
this.dom.runner.onEvent("footstep", () => AudioManager.PlaySFX("step"));
},
getPartTransform
element.getPartTransform(part: string, origin: "pivot" | "center" = "pivot"): SpriteLoopPartTransform | null
Returns where a part is on the current frame, in the node's own pixels: x, y, rotation, scaleX, scaleY, skewX, skewY and opacity. origin chooses the part's pivot or the centre of its image. Returns null if the part isn't in the frame.
Example
checkHand() {
const hand = this.dom.knight.getPartTransform("right_hand");
if (hand) log(`Hand is at ${hand.x}, ${hand.y} inside the knight node`); // not screen coordinates
},
Spine nodes
Spine nodes (see Spine) add these controls.
| Member | Description |
|---|---|
animations |
The names of the skeleton's animations |
currentAnimation |
The animation playing now, or null |
skins |
The skeleton's skins, not counting "default" |
currentSkins |
The skins shown now, in the order they're combined |
play(animation?, options?) |
Plays an animation from the start |
pause() |
Freezes the animation |
resume() |
Carries on after pause() |
stop() |
Stops and goes back to the setup pose |
setSkins(skins) |
Shows these skins combined |
play (Spine)
element.play(animation?: string, options?: { loop?: boolean; speed?: number }): Promise<void>
| Parameter | Type | Default | Description |
|---|---|---|---|
animation |
string |
The current animation | The animation's name |
options.loop |
boolean |
true |
false to play once |
options.speed |
number |
1 |
Playback speed |
Returns a promise that resolves when a play-once animation ends, or when it's replaced or stopped.
Example
async onWave() {
await this.dom.fox.play("wave", { loop: false });
this.dom.fox.play("idle");
},
setSkins
element.setSkins(skins: string | string[]): boolean
Shows these skins combined, in order, with later ones winning where they overlap. The "default" skin always applies underneath. Pass [] to leave only "default".
Returns false if any name doesn't exist. The skins that do exist are still applied.
Example
onStart() {
this.dom.fox.setSkins(["body/red", "hat/straw"]);
},
Checkbox nodes
Checkbox nodes (see Checkbox) change two properties.
| Member | Description |
|---|---|
checked: boolean |
true while ticked. Setting it ticks or unticks the box, without calling On Change |
textContent: string |
The label's text. Setting it changes only the label |
Example
onEnter() {
this.dom.fullscreen_box.checked = Application.IsFullscreen();
this.dom.fullscreen_box.textContent = "Fullscreen";
},