Skip to content

Commit

Permalink
Change logic for emitting sound events.
Browse files Browse the repository at this point in the history
  • Loading branch information
isadorasophia committed Dec 3, 2023
1 parent 192a2db commit 68b9846
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/Murder.Editor/Systems/Debug/AnimationEventDebugSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
6 changes: 6 additions & 0 deletions src/Murder/Services/EntityServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/Murder/Systems/Effects/EventListenerSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void OnMessage(World world, Entity entity, IMessage message)

// Were we actually listening to this particular event?
ImmutableDictionary<string, SpriteEventInfo> 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)
Expand Down

0 comments on commit 68b9846

Please sign in to comment.