fx
fx Module
The fx module provides static utility methods to trigger visual screen effects (such as fades and flashes), spawn 3D pooled visual effects, and play 2D or 3D positional audio and background music.
All methods are called directly on the fx global table using dot syntax (e.g. fx.fade(...)).
Overview
Methods (12)
| Method Signature | Returns | Summary |
|---|---|---|
fx.fade(color, [fadeInDuration = 0], [delay = 0], [fadeOutDuration = 0])
|
void
|
Performs a full screen fade-in, hold delay, and fade-out sequence. |
fx.fadeIn(color, [duration = 1])
|
void
|
Fades the screen in to solid color. |
fx.fadeOut([duration = 1])
|
void
|
Fades the screen back to normal transparent view. |
fx.flash(color, [duration = 0.5], [delay = 0])
|
void
|
Flashes the screen with color overlay. |
fx.playEffect(path, [position], [rotation], [lifeTime = 5])
|
boolean
|
Spawns a pooled 3D visual particle effect in the world. |
fx.playMusic(path)
|
void
|
Plays a background music track. |
fx.playSound(path, [volume = 1], [pitch = 1], [bus = "Effects"])
|
void
|
Plays a 2D non-positional sound effect. |
fx.playSoundAt(path, [position], [volume = 1], [pitch = 1], [bus = "Effects"])
|
void
|
Plays a 3D positional sound effect in the world. |
fx.stopAllSounds()
|
void
|
Stops all sound effects currently playing. |
fx.stopFade()
|
void
|
Immediately cancels any active screen fade. |
fx.stopMusic()
|
void
|
Stops background music playback. |
fx.stopSound(path)
|
void
|
Stops playing sound instances matching path. |
Detailed Reference
fx.fade(color, [fadeInDuration = 0], [delay = 0], [fadeOutDuration = 0])| Parameter | Type | Default | Description |
|---|---|---|---|
color | color|string|number | Target color (color object, hex string, or integer color value). | |
fadeInDuration | number | `0` | Fade-in duration in seconds. |
delay | number | `0` | Hold time in seconds at peak opacity. |
fadeOutDuration | number | `0` | Fade-out duration back to normal in seconds. |
Overlays the screen with a solid color, holds it for delay seconds, and then transitions back out.
-- Flash screen red quickly and fade out over 1 second
fx.fade(color.new(1, 0, 0), 0.1, 0.2, 1.0)fx.fadeIn(color, [duration = 1])| Parameter | Type | Default | Description |
|---|---|---|---|
color | color|string|number | Target fade color. | |
duration | number | `1` | Transition time in seconds. |
Transitions screen overlay from transparent to opaque color.
fx.fadeOut([duration = 1])| Parameter | Type | Default | Description |
|---|---|---|---|
duration | number | `1` | Fade-out duration in seconds. |
Fades active color overlay out.
fx.flash(color, [duration = 0.5], [delay = 0])| Parameter | Type | Default | Description |
|---|---|---|---|
color | color|string|number | Flash color. | |
duration | number | `0.5` | Flash duration in seconds. |
delay | number | `0` | Hold delay before fade-out. |
Quickly flashes the screen with color (e.g. damage flash or lightning).
fx.playEffect(path, [position], [rotation], [lifeTime = 5])| Parameter | Type | Default | Description |
|---|---|---|---|
path | string | Resource path to VFX prefab (e.g. | |
position | vector3 | `(0, 0, 0)` | 3D world position. |
rotation | vector3|quaternion | `(0, 0, 0)` | Euler rotation in degrees or quaternion. |
lifeTime | number | `5` | Despawn lifetime in seconds. |
booleantrue if spawned successfully.
Spawns a visual particle prefab from the VFX pool at the given world coordinates.
fx.playMusic(path)| Parameter | Type | Default | Description |
|---|---|---|---|
path | string | Music stream resource path. |
Transitions and loops background music track from path.
fx.playSound(path, [volume = 1], [pitch = 1], [bus = "Effects"])| Parameter | Type | Default | Description |
|---|---|---|---|
path | string | Audio stream resource path. | |
volume | number | `1` | Playback volume scale. |
pitch | number | `1` | Pitch scale factor. |
bus | string | `"Effects"` | Godot audio bus name. |
Plays an audio stream across stereo speakers without 3D attenuation (e.g. UI clicks, stingers).
fx.playSound("res://audio/ui_click.ogg", 0.8, 1.0)fx.playSoundAt(path, [position], [volume = 1], [pitch = 1], [bus = "Effects"])| Parameter | Type | Default | Description |
|---|---|---|---|
path | string | Audio stream resource path. | |
position | vector3 | `(0, 0, 0)` | 3D world coordinates. |
volume | number | `1` | Volume scale. |
pitch | number | `1` | Pitch scale. |
bus | string | `"Effects"` | Audio bus name. |
Plays audio in 3D space with distance attenuation and panning relative to player camera.
fx.playSoundAt("res://audio/explosion.ogg", e.position, 1.0, 1.0)fx.stopAllSounds()Immediately stops all active sound effect channels.
fx.stopFade()Instantly resets the screen fade overlay back to clear.
fx.stopMusic()Halts any active background music.
fx.stopSound(path)| Parameter | Type | Default | Description |
|---|---|---|---|
path | string | Audio stream path. |
Stops all audio players currently playing the specified audio stream.