In short.
melonjs-events is a coding-assistant skill for melonJS developers managing events and object lifecycles, but its version-sensitive guidance needs checking against the project's engine release. It explains how listener identity affects removal, why reused objects need cleanup during deactivation, and how loading or collision callbacks can cause unexpected behavior. No code was executed, and the supplied documents do not establish runtime correctness or a supported version range.
Researched and written by an AI model and checked by a second AI model. How it works
The complete selected scope is packages/melonjs/skills/melonjs-events at revision 837bd09106a0dcd1f4e4925a2b8a25cbcbdfc33c, containing SKILL.md. The repository-root LICENSE.md is included as a related notice outside that folder. Engine source, package configuration, release history and related skills are outside the supplied scope. The skill and examples were not installed, executed or tested; runtime behavior and compatibility remain unverified.
The overview
Identity
melonjs-events is an instruction file in the melonjs/melonJS repository at packages/melonjs/skills/melonjs-events/SKILL.md. Its declared scope is the melonJS event bus and lifecycle hooks, including subscriptions, engine event names and renderable callbacks.
It supplies guidance and JavaScript examples for coding assistants. The selected folder contains one captured file, SKILL.md.
Assessment
The document is particularly useful for investigating handlers that survive object removal, callbacks that accumulate when objects are reused, loading callbacks that run again during play, and crashes during state changes or collisions. Its troubleshooting table connects these symptoms to specific API and lifecycle mistakes.
Its practical strength is the explanation of cleanup responsibilities across normal removal, pooling and destruction. Those explanations are documented claims; their accuracy for a particular engine release has not been independently established.
Users
Beginners working on a melonJS game get a reference to common events and the callbacks the engine invokes when objects enter or leave the world. They will need enough JavaScript knowledge to follow imports, object methods, function binding and callbacks.
Experienced developers may find the details about handler and context identity, pooled-object cleanup, TypeScript event names and collision-time removal especially relevant when diagnosing intermittent bugs.
Capabilities
The skill explains event.on, event.once, event.off and the unsubscribe function returned by event.on. It lists update, draw, physics, startup, state, loading, focus, resize and pointer events.
It also covers activation, deactivation and destruction callbacks; delayed activation in detached containers; persistent renderables; pooled objects; teardown guards; and deferred object removal from collision callbacks. It provides a symptom-to-cause table and references two related skills.
Using it
Requirements
The examples assume a project using melonJS and access to its event API. Some patterns also require the input and state APIs or methods on a renderable object.
The document does not specify a minimum supported melonJS version, build configuration, compatible assistant, model or skill installation location. TypeScript users must account for its warning that the engine's event types accept a fixed set of event names.
Mechanism
The event bus calls a function registered for an event. According to the skill, manual removal with event.off must match both the original function and its context object. Creating a fresh bound function for removal will not match the registered one. Keeping the unsubscribe function returned by event.on is another documented removal method.
The lifecycle guidance pairs registration in onActivateEvent with cleanup in onDeactivateEvent. This matters because returning an object to a pool can bypass destruction. The document also says activation waits until an object reaches the world through its container, while persistent objects receive no fresh activation merely because the state changes.
Setup
Read SKILL.md alongside documentation for the melonJS release used by the project. An assistant would need to load the file through its own supported instruction mechanism; this resource supplies no host-specific installation procedure.
For the game code, identify where each listener is registered and which lifecycle callback removes it. Retain either the original handler and context or the returned unsubscribe function. Pointer registrations require their own release when pooled objects deactivate, according to the document.
Example
An adaptation of the documented pattern registers event.on(event.GAME_UPDATE, this.tick, this) inside onActivateEvent(), then calls event.off(event.GAME_UPDATE, this.tick, this) inside onDeactivateEvent(). The same method reference and object context appear in both calls, allowing the subscription to be matched for removal. This illustrative pattern was not executed.
For a loading callback intended to run only once, the skill recommends event.once(event.LOADER_COMPLETE, callback) or the completion mechanism on preload itself. Its reason is that later preload calls and bundle loads can emit LOADER_COMPLETE again.
Assessment & evidence
Limitations
The examples are partial patterns. The supplied material contains no engine implementation, complete project setup, compatibility results or measured performance improvements.
The skill warns that GAME_UPDATE does not fire while paused and that draw events occur only on frames that redraw. It also says custom event names work at runtime but fall outside the engine's closed TypeScript event map. These details limit where otherwise similar event-handling patterns can be applied.
Reasoning
The resource's strongest explanation is the connection between object reuse and cleanup: an object can leave the world without being destroyed, so cleanup placed only in onDestroyEvent can miss that path. Pairing activation and deactivation gives developers a specific lifecycle boundary to examine.
Its collision guidance follows a similar causal explanation. The document says contact callbacks run during physics iteration, so immediate removal can tear down an object while that iteration is still using it. It recommends deferred removeChild() or processing flagged work in Stage.update. These mechanisms make the advice useful to investigate, although their implementation was not assessed.
Alternatives
Within melonJS, the skill recommends renderable lifecycle callbacks where they fit because they avoid an additional bus subscription. For custom game events in TypeScript, it suggests a separate emitter without naming a particular library.
It points to melonjs-scenes-and-state for state transitions and stage lifecycle, and melonjs-performance for pooling. Those resources were not supplied, so their contents and relative usefulness are unknown.
Evidence
The source is fixed to repository revision 837bd09106a0dcd1f4e4925a2b8a25cbcbdfc33c. The original skill file is available at [https://raw.githubusercontent.com/melonjs/melonJS/837bd09106a0dcd1f4e4925a2b8a25cbcbdfc33c/packages/melonjs/skills/melonjs-events/SKILL.md]. Its recorded SHA-256 is c6ebf19353be9b2f72d6c79a430f59c441116fa664d0e09e7da2efc1c8632c32.
The accompanying repository licence is available at [https://raw.githubusercontent.com/melonjs/melonJS/837bd09106a0dcd1f4e4925a2b8a25cbcbdfc33c/LICENSE.md]. These two documents establish the instruction content and permission terms. They do not independently establish the described engine behavior.
Access & freshness
Costs
Neither document states a purchase price, subscription price, assistant usage rate or operating cost. Total cost is unknown. Any charges for an assistant, development tools or running a game are unspecified.
The MIT notice grants broad usage and redistribution rights, but it does not establish the cost of a complete development setup.
Rights
SKILL.md declares MIT licensing, and the repository's LICENSE.md supplies the MIT permission grant. It permits use, copying, modification, publication, distribution, sublicensing and sale of copies, provided the copyright and permission notices remain with copies or substantial portions.
The notice identifies Olivier Biot (AltByte Pte Ltd) as the copyright holder and provides the software without warranty, with a liability disclaimer.
Freshness
The source snapshot was captured on 2026-11-16 at 12:07:41.416 UTC. That capture time does not establish when the skill was last edited or whether it matches the newest engine release.
The skill describes loader callback properties deprecated in 18.2.0 and removed in 20.3, a deactivation fix in 20.13.0, and bundle-loading event behavior associated with 20.14. These are claims in the document; release dates, release history and compatibility with other versions are unverified.
Actions
Before applying the examples, compare the installed melonJS version with the document's loader and lifecycle notes. Trace subscriptions through activation, deactivation and pool reuse, preserving the original handler and context or unsubscribe function.
Suggested validation includes switching states, repeatedly reusing pooled objects, and triggering another asset load while checking for duplicate callbacks or missed cleanup. Inspect collision callbacks for immediate removal and consider the documented deferred-removal pattern. None of these checks has been run.
