Skip to main content

One post tagged with "gamedev excaliburjs architecture events ai"

View All Tags

Event-Driven Gameplay in ExcaliburJS

· 10 min read
Justin Young
Excalibur Contributor

A Primer on Excalibur Event Emitters

Pubsub model

Intro

As your game grows, so does the complexity of its logic.

Enemies need to react to the player. Animations need to trigger damage. AI systems need to coordinate state changes. UI needs to update when something happens — but that “something” might come from anywhere.

One approach is direct calls:

ts
enemy.takeDamage(10);
enemy.die();
hud.updateHealth();
sound.play();
ts
enemy.takeDamage(10);
enemy.die();
hud.updateHealth();
sound.play();

This works… until it doesn’t.

Suddenly everything knows about everything else. A small change in one system ripples through your entire codebase. Reuse becomes difficult. Debugging becomes painful.

This is where event-driven architecture shines — and ExcaliburJS provides a powerful, flexible event system that can be used as a tool to connect different systems.

In this article, we’ll explore:

  • What Excalibur’s event framework actually gives you
  • Why publish/subscribe (pub/sub) patterns matter in games
  • Practical, real-world use cases
  • And how to model gameplay events, not just callbacks

Events are a tool. Any tool can help you solve a specific set of problems. As with any other tool, if you start applying this solution to the wrong problems, there are potential foot-guns. We will discuss this a bit.