Skip to content

Class: EffectsManager ✨

Source: core/EffectsManager.js, line 19

The EffectsManager is responsible for handling and applying visual effects to the game screen. It acts as a central hub for triggering, updating, and rendering effects like screen shake, flashes, and color tints. It typically operates as a post-processing step, taking the fully rendered scene (usually on an offscreen canvas) and applying its effects before drawing the final image to the visible canvas.


Constructor

new EffectsManager(engine)

Creates a new EffectsManager instance.

Parameters:

NameTypeDescription
engineIroncladEngineA reference to the main game engine instance, providing access to other services and the canvas.

Source: core/EffectsManager.js, line 19


Methods

addEffect(effectInstance)

Adds a custom effect instance to the manager. The effect should conform to an expected interface, likely having update(deltaTime) and apply(context, canvas) methods.

Parameters:

NameTypeDescription
effectInstanceBaseEffectAn instance of an effect class (e.g., FlashEffect, ShakeEffect, or a custom effect).

Source: core/EffectsManager.js, line 44


clearAllEffects()

Immediately removes and stops all currently active visual effects.

Source: core/EffectsManager.js, line 262


clearTint()

Specifically removes any active persistent screen tint effect.

Source: core/EffectsManager.js, line 154


flash(color?, duration?, maxOpacity?, fadeOut?)

Triggers a screen flash effect. This is a convenient shortcut that creates and adds a FlashEffect instance. 💥

Parameters:

NameTypeAttributesDefaultDescription
colorstringoptional'rgba(255, 255, 255, 0.5)'The color of the flash (CSS color string).
durationnumberoptional300The total duration of the flash in milliseconds.
maxOpacitynumberoptional0.7The peak opacity of the flash (0.0 to 1.0).
fadeOutbooleanoptionaltrueWhether the flash should fade out over its duration.

Source: core/EffectsManager.js, line 91


postRender(mainContext, sceneCanvas)

This is a key method called by the engine's main render loop after the scene has been drawn to an offscreen canvas. It takes the scene canvas, applies all active effects (like shake and tint), and then draws the final, potentially modified, image onto the main visible canvas context.

Parameters:

NameTypeDescription
mainContextCanvasRenderingContext2DThe 2D rendering context of the visible main canvas.
sceneCanvasHTMLCanvasElementThe offscreen canvas containing the already-rendered scene.

Source: core/EffectsManager.js, line 214


shake(intensity?, duration?, decay?)

Triggers a screen shake effect. This is a convenient shortcut that creates and adds a ShakeEffect instance. 地震

Parameters:

NameTypeAttributesDefaultDescription
intensitynumberoptional10The maximum pixel offset (both X and Y) for the shake.
durationnumberoptional500The duration of the shake effect in milliseconds.
decaybooleanoptionaltrueWhether the shake intensity should decrease (decay) over its duration.

Source: core/EffectsManager.js, line 70


tint(color?, opacity?)

Applies or updates a persistent screen tint effect. This creates or modifies a TintEffect. You can use this to color the whole screen (e.g., for nighttime scenes, damage indicators, or transitions). Call clearTint() or tint('rgba(0,0,0,0)', 0) to remove it.

Parameters:

NameTypeAttributesDefaultDescription
colorstringoptional'rgba(0,0,0,0)'The color to tint the screen with (CSS color string).
opacitynumberoptional0The opacity of the tint (0.0 for none, 1.0 for full).

Source: core/EffectsManager.js, line 112


update(deltaTime)

Updates the state of all active effects. It calls the update method on each effect instance, allowing them to progress (e.g., fade out, decay). It also removes any effects that have finished their duration. This method is typically called once per frame by the main engine loop.

Parameters:

NameTypeDescription
deltaTimenumberThe time elapsed since the last frame, in seconds.

Source: core/EffectsManager.js, line 176

Released under the MIT License (Placeholder).