public Animation( AnimationBase animBase, bool loopForever, bool autoRotate = false, int zDimension = -1, Entity parent = null ) { MyBase = animBase; mParent = parent; if (MyBase != null) { mLowerLoop = animBase.Lower.LoopCount; mUpperLoop = animBase.Upper.LoopCount; mLowerTimer = Globals.System.GetTimeMs() + animBase.Lower.FrameSpeed; mUpperTimer = Globals.System.GetTimeMs() + animBase.Upper.FrameSpeed; InfiniteLoop = loopForever; AutoRotate = autoRotate; mZDimension = zDimension; mSound = Audio.AddMapSound(MyBase.Sound, 0, 0, Guid.Empty, loopForever, 0, 12, parent); lock (Graphics.AnimationLock) { Graphics.LiveAnimations.Add(this); } } else { Dispose(); } }
//Updating public void Update(bool isLocal) { if (isLocal) { mLastUpdateTime = Globals.System.GetTimeMs() + 10000; UpdateMapAttributes(); if (BackgroundSound == null && !TextUtils.IsNone(Sound)) { BackgroundSound = Audio.AddMapSound(Sound, -1, -1, Id, true, 0, 10); } foreach (var anim in LocalAnimations) { if (anim.Value.Disposed()) { LocalAnimations.TryRemove(anim.Key, out MapAnimation removed); } else { anim.Value.Update(); } } foreach (var en in LocalEntities) { if (en.Value == null) { continue; } en.Value.Update(); } foreach (var critter in mAttributeCritterInstances) { if (critter.Value == null) { continue; } critter.Value.Update(); } for (var i = 0; i < LocalEntitiesToDispose.Count; i++) { LocalEntities.Remove(LocalEntitiesToDispose[i]); } LocalEntitiesToDispose.Clear(); } else { if (Globals.System.GetTimeMs() > mLastUpdateTime) { Dispose(); } HideActiveAnimations(); } }
void MapMute(bool mute) { if (world != null) { MapSound sound = world.GetComponent <MapSound>(); if (sound != null) { sound.mute = mute; } } }
//Sounds public static MapSound AddMapSound( string filename, int x, int y, Guid mapId, bool loop, int distance, Entity parent = null ) { if (sGameSounds?.Count > 128) { return(null); } var sound = new MapSound(filename, x, y, mapId, loop, distance, parent); sGameSounds?.Add(sound); return(sound); }
public void Dispose() { if (disposed) { return; } lock (Graphics.AnimationLock) { if (mSound != null) { mSound.Loop = false; if (!MyBase.CompleteSound) { mSound.Stop(); } mSound = null; } Graphics.LiveAnimations.Remove(this); disposed = true; } }
public static void StopSound(MapSound sound) { sound?.Stop(); }