@tool @icon("res://addons/gd-dynamic-sound/icon.svg") class_name DynamicSoundFXPlayer2D ## 2D positional variant of [DynamicSoundFXPlayer]. ## ## Each [method play_fx] call triggers a fresh play of the assigned ## [DynamicSound], layered with any plays still in flight, distance-attenuated ## from a 2D position relative to the listener. extends AudioStreamPlayer2D ## The [DynamicSound] to trigger. Each [method play_fx] call plays a fresh instance. @export var Sound : DynamicSound; ## Volume mix between intensity layers. Only blended when all three layers are set. @export_range(0, 1) var Intensity : float = 0; ## How playback pitch is selected for each [method play_fx] trigger. @export var PitchMode : DynamicSoundConstants.PitchMode = DynamicSoundConstants.PitchMode.Constant: set(value): PitchMode = value; notify_property_list_changed(); ## Minimum pitch offset (added to 1.0) when [member PitchMode] is Random. @export var RandomMinPitchScale : float = -0.5; ## Maximum pitch offset (added to 1.0) when [member PitchMode] is Random. @export var RandomMaxPitchScale : float = 0.5; var _core : DynamicSoundFXPlayerCore; func _enter_tree() -> void: if not Engine.is_editor_hint(): return; if stream == null: stream = AudioStreamPolyphonic.new(); if bus == &"Master" and AudioServer.get_bus_index("FX") != -1: bus = "FX"; func _validate_property(property: Dictionary) -> void: if property.name in ["RandomMinPitchScale", "RandomMaxPitchScale"]: if PitchMode != DynamicSoundConstants.PitchMode.Random: property.usage &= ~PROPERTY_USAGE_EDITOR; func _ready() -> void: _core = DynamicSoundFXPlayerCore.new(self); _core.ready(); ## Trigger a one-shot of [member Sound]. Layers with any in-flight triggers. func play_fx() -> void: if _core: _core.play_fx();