protected override async Task OnActivatedAsync(ActorActivationDetails details) { // ToDo: Implement Fade:1|Sine:1 CollisionFlags = CollisionFlags.ForceDisableCollisions; await RequestMetadataAsync("Common/AmbientSound"); string name; switch (details.Params[0]) { case 0: name = "AmbientWind"; break; case 1: name = "AmbientFire"; break; case 2: name = "AmbientScienceNoise"; break; default: return; } float gain = (details.Params[1] / 255f); sound = PlaySound(name, gain); if (sound != null) { sound.Flags |= SoundInstanceFlags.Looped; sound.BeginFadeIn(1f); } }
public override void OnAttach(ActorInstantiationDetails details) { base.OnAttach(details); // ToDo: Implement Fade:1|Sine:1 collisionFlags = CollisionFlags.None; RequestMetadata("Common/AmbientSound"); string name; switch (details.Params[0]) { case 0: name = "AmbientWind"; break; case 1: name = "AmbientFire"; break; case 2: name = "AmbientScienceNoise"; break; default: return; } float gain = (details.Params[1] / 255f); sound = PlaySound(name, gain); sound.Looped = true; sound.BeginFadeIn(1f); }
/// <summary> /// Plays a music/ambience/etc. sound. The previously played music fades out. /// </summary> /// <param name="music">The sound resource to play.</param> /// <param name="volume">The playback volume of sound to play. Ranging from 0f to 1f.</param> /// <param name="fadeSeconds">The time this piece takes to fade in, and the previous piece to fade out.</param> /// <param name="looped">Wheter the piece should be looped or not.</param> public static void PlayMusic(ContentRef <Sound> music, float volume = 1f, float fadeSeconds = 1f, bool looped = true) { if (musicInstance != null && !musicInstance.Paused) { musicInstance.FadeOut(fadeSeconds); } musicInstance = DualityApp.Sound.PlaySound(music); musicInstance.Looped = looped; musicInstance.BeginFadeIn(fadeSeconds); }
public static void BeginIntro(ContentRef <Sound> _m) { FadeOutMusic(); //var intro = ContentProvider.RequestContent<Sound>(Combine(DualityApp.DataDirectory, "MainGame", "Sounds", "ForestOverworld.Sound.res")); if (_m != null) { mus = DualityApp.Sound.PlaySound(_m); mus.Looped = true; mus.BeginFadeIn(5f); } }
static public void PlayMusic(ContentRef <Sound> musicRef) { if (musicSoundInstance == null) { musicSoundInstance = DualityApp.Sound.PlaySound(musicRef); musicSoundInstance.Looped = true; } else if (musicSoundInstance.Sound != musicRef) { musicSoundInstance.FadeOut(2); musicSoundInstance = DualityApp.Sound.PlaySound(musicRef); musicSoundInstance.Looped = true; musicSoundInstance.BeginFadeIn(2); } }
void ICmpUpdatable.OnUpdate() { GamepadInput gamepad = DualityApp.Gamepads[0]; Vector2 moveDir = gamepad.LeftThumbstick.Normalized; float moveSpeed = MathF.Clamp((gamepad.LeftThumbstick.Length - 0.3f) / 0.7f, 0.0f, 1.0f); Vector2 lookDir = gamepad.RightThumbstick.Normalized; float lookIntensity = MathF.Clamp((gamepad.RightThumbstick.Length - 0.3f) / 0.7f, 0.0f, 1.0f); this.controlTarget.ThrusterActivity = moveDir * moveSpeed; this.controlTarget.RotateActivity = lookDir * lookIntensity; if (gamepad.RightTrigger > 0.5f) { this.controlTarget.FireWeapons(); } if (gamepad.ButtonHit(GamepadButton.Start)) { if (musicInstance != null && !musicInstance.Disposed) { musicInstance.Lowpass = 1.0f; } Scene.Reload(); } if (gamepad.ButtonHit(GamepadButton.Back)) { DualityApp.Terminate(); } if (musicInstance == null || musicInstance.Disposed) { musicInstance = DualityApp.Sound.PlaySound(this.backgroundMusic); musicInstance.Looped = true; musicInstance.Volume = 0.4f; musicInstance.BeginFadeIn(5.0f); } else { float targetLowPass = 1.0f; if (this.controlTarget == null || this.controlTarget.Disposed) { targetLowPass = 0.05f; } else { targetLowPass = 1.0f; } float changeDir = MathF.Sign(targetLowPass - musicInstance.Lowpass); float changeAbs = MathF.Abs(targetLowPass - musicInstance.Lowpass); if (changeAbs <= 0.01f) { musicInstance.Lowpass = targetLowPass; } else { musicInstance.Lowpass += changeDir * Time.TimeMult * Time.SPFMult / 8.0f; } } }