From cc0ac1523beba2b525392aff64144c38d18b0fa1 Mon Sep 17 00:00:00 2001 From: MEEPofFaith <54301439+MEEPofFaith@users.noreply.github.com> Date: Tue, 30 Jan 2024 07:45:38 -0800 Subject: [PATCH] SoundEffect's sound should be delayed by its startDelay (#9502) * SoundEffect's sound should be delayed by its startDelay * h --- .../mindustry/entities/effect/SoundEffect.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/core/src/mindustry/entities/effect/SoundEffect.java b/core/src/mindustry/entities/effect/SoundEffect.java index 8ed0f74a20..c3d320d527 100644 --- a/core/src/mindustry/entities/effect/SoundEffect.java +++ b/core/src/mindustry/entities/effect/SoundEffect.java @@ -21,18 +21,32 @@ public class SoundEffect extends Effect{ public Effect effect; public SoundEffect(){ + startDelay = -1; } public SoundEffect(Sound sound, Effect effect){ + this(); this.sound = sound; this.effect = effect; } + @Override + public void init(){ + if(startDelay < 0){ + startDelay = effect.startDelay; + } + } + @Override public void create(float x, float y, float rotation, Color color, Object data){ if(!shouldCreate()) return; - sound.at(x, y, Mathf.random(minPitch, maxPitch), Mathf.random(minVolume, maxVolume)); + if(startDelay > 0){ + Time.run(startDelay, () -> sound.at(x, y, Mathf.random(minPitch, maxPitch), Mathf.random(minVolume, maxVolume))); + }else{ + sound.at(x, y, Mathf.random(minPitch, maxPitch), Mathf.random(minVolume, maxVolume)); + } + effect.create(x, y, rotation, color, data); } }