Dev » Lua API » fx
← Back to all classes

fx

Effects & Audio 12 Methods

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

# fade METHOD
fx.fade(color, [fadeInDuration = 0], [delay = 0], [fadeOutDuration = 0])
Performs a full screen fade-in, hold delay, and fade-out sequence.
Parameters
ParameterTypeDefaultDescription
colorcolor|string|number

Target color (color object, hex string, or integer color value).

fadeInDurationnumber`0`

Fade-in duration in seconds.

delaynumber`0`

Hold time in seconds at peak opacity.

fadeOutDurationnumber`0`

Fade-out duration back to normal in seconds.

Returns
None (void)
Description

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)
# fadeIn METHOD
fx.fadeIn(color, [duration = 1])
Fades the screen in to solid color.
Parameters
ParameterTypeDefaultDescription
colorcolor|string|number

Target fade color.

durationnumber`1`

Transition time in seconds.

Returns
None (void)
Description

Transitions screen overlay from transparent to opaque color.

# fadeOut METHOD
fx.fadeOut([duration = 1])
Fades the screen back to normal transparent view.
Parameters
ParameterTypeDefaultDescription
durationnumber`1`

Fade-out duration in seconds.

Returns
None (void)
Description

Fades active color overlay out.

# flash METHOD
fx.flash(color, [duration = 0.5], [delay = 0])
Flashes the screen with color overlay.
Parameters
ParameterTypeDefaultDescription
colorcolor|string|number

Flash color.

durationnumber`0.5`

Flash duration in seconds.

delaynumber`0`

Hold delay before fade-out.

Returns
None (void)
Description

Quickly flashes the screen with color (e.g. damage flash or lightning).

# playEffect METHOD
fx.playEffect(path, [position], [rotation], [lifeTime = 5])
Spawns a pooled 3D visual particle effect in the world.
Parameters
ParameterTypeDefaultDescription
pathstring

Resource path to VFX prefab (e.g. "res://vfx/sparks.tscn").

positionvector3`(0, 0, 0)`

3D world position.

rotationvector3|quaternion`(0, 0, 0)`

Euler rotation in degrees or quaternion.

lifeTimenumber`5`

Despawn lifetime in seconds.

Returns
boolean

true if spawned successfully.

Description

Spawns a visual particle prefab from the VFX pool at the given world coordinates.

# playMusic METHOD
fx.playMusic(path)
Plays a background music track.
Parameters
ParameterTypeDefaultDescription
pathstring

Music stream resource path.

Returns
None (void)
Description

Transitions and loops background music track from path.

# playSound METHOD
fx.playSound(path, [volume = 1], [pitch = 1], [bus = "Effects"])
Plays a 2D non-positional sound effect.
Parameters
ParameterTypeDefaultDescription
pathstring

Audio stream resource path.

volumenumber`1`

Playback volume scale.

pitchnumber`1`

Pitch scale factor.

busstring`"Effects"`

Godot audio bus name.

Returns
None (void)
Description

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)
# playSoundAt METHOD
fx.playSoundAt(path, [position], [volume = 1], [pitch = 1], [bus = "Effects"])
Plays a 3D positional sound effect in the world.
Parameters
ParameterTypeDefaultDescription
pathstring

Audio stream resource path.

positionvector3`(0, 0, 0)`

3D world coordinates.

volumenumber`1`

Volume scale.

pitchnumber`1`

Pitch scale.

busstring`"Effects"`

Audio bus name.

Returns
None (void)
Description

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)
# stopAllSounds METHOD
fx.stopAllSounds()
Stops all sound effects currently playing.
Parameters
None
Returns
None (void)
Description

Immediately stops all active sound effect channels.

# stopFade METHOD
fx.stopFade()
Immediately cancels any active screen fade.
Parameters
None
Returns
None (void)
Description

Instantly resets the screen fade overlay back to clear.

# stopMusic METHOD
fx.stopMusic()
Stops background music playback.
Parameters
None
Returns
None (void)
Description

Halts any active background music.

# stopSound METHOD
fx.stopSound(path)
Stops playing sound instances matching path.
Parameters
ParameterTypeDefaultDescription
pathstring

Audio stream path.

Returns
None (void)
Description

Stops all audio players currently playing the specified audio stream.