From 68b9846b3c8b9471bd0eb98959b9ba015ad2c76d Mon Sep 17 00:00:00 2001 From: bonnibel Date: Sat, 2 Dec 2023 16:53:42 -0800 Subject: [PATCH] Change logic for emitting sound events. --- .../Systems/Debug/AnimationEventDebugSystem.cs | 3 ++- src/Murder/Services/EntityServices.cs | 6 ++++++ src/Murder/Systems/Effects/EventListenerSystem.cs | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Murder.Editor/Systems/Debug/AnimationEventDebugSystem.cs b/src/Murder.Editor/Systems/Debug/AnimationEventDebugSystem.cs index 8fb07b727..e49de1e8a 100644 --- a/src/Murder.Editor/Systems/Debug/AnimationEventDebugSystem.cs +++ b/src/Murder.Editor/Systems/Debug/AnimationEventDebugSystem.cs @@ -28,6 +28,7 @@ public void OnMessage(World world, Entity entity, IMessage message) } AnimationEventMessage msg = (AnimationEventMessage)message; - DebugServices.DrawText(world, msg.Event, entity.GetGlobalTransform().Vector2 + new System.Numerics.Vector2(Game.Random.NextFloat(-5, 5), Game.Random.NextFloat(-5, 5)), 0.5f); + DebugServices.DrawText(world, msg.Event, entity.GetGlobalTransform().Vector2 + + new System.Numerics.Vector2(Game.Random.NextFloat(-5, 5), Game.Random.NextFloat(-5, 5)), 0.5f); } } \ No newline at end of file diff --git a/src/Murder/Services/EntityServices.cs b/src/Murder/Services/EntityServices.cs index a3d2a4fc8..7410e6bdd 100644 --- a/src/Murder/Services/EntityServices.cs +++ b/src/Murder/Services/EntityServices.cs @@ -287,6 +287,12 @@ public static void Spawn(World world, Vector2 spawnerPosition, Guid entityToSpaw public static bool IsInCamera(this Entity e, World world) { + if (!e.HasTransform()) + { + // No transform? Assume it's ~*everywhere~*. + return true; + } + Point p = e.GetGlobalTransform().Point; return ((MonoWorld)world).Camera.SafeBounds.Contains(p); diff --git a/src/Murder/Systems/Effects/EventListenerSystem.cs b/src/Murder/Systems/Effects/EventListenerSystem.cs index 5a34afc15..f42f986aa 100644 --- a/src/Murder/Systems/Effects/EventListenerSystem.cs +++ b/src/Murder/Systems/Effects/EventListenerSystem.cs @@ -29,7 +29,7 @@ public void OnMessage(World world, Entity entity, IMessage message) // Were we actually listening to this particular event? ImmutableDictionary events = entity.GetEventListener().Events; - if (events.TryGetValue(animationEvent.Event, out SpriteEventInfo info)) + if (entity.IsInCamera(world) && events.TryGetValue(animationEvent.Event, out SpriteEventInfo info)) { // Start doing event actions. if (info.Sound is SoundEventId sound)