Excalibur.js Documentation
website·Indexed 33 days ago
https://excaliburjs.com/docs/A 2D game engine featuring an Entity Component System (ECS) architecture. Documentation covers core concepts including Colliders, Graphics, Actions, and Custom Components, as well as implementation details for collision groups, action queues, and async flow.
What's inside Excalibur.js
- Excalibur is a free, open-source 2D game engine written in TypeScript designed for creating web-based games. It aims to reduce boilerplate code and handle cross-platform targeting, providing a "batteries included" experience with sensible defaults to allow developers to focus on game design and building.
Overview of the Collider class
TheColliderclass specifies the geometry used to detect when two objects in Excalibur intersect. It serves as the base class for specific collider shapes includingCircleCollider,EdgeCollider,PolygonCollider, andCompositeCollider. It implements theClonableinterface.Overview of the LightingSystem
The
LightingSystemis a composite canvas-driven visibility system that tracks ambient light, darkness, light masks, and ray-projected shadow volumes. It renders via aScreenElementnamed 'lighting'.The raster pipeline per frame follows this sequence: ambient-blended darkness veil → room rect fills/clips → camera frustum cull → per-light destination-out punch (with occluder shadows subtracted) → colored tint passes.
Performance Note: The overlay is rasterized using the 2D Canvas API and re-uploaded to the GPU every frame, which can impact performance.
Known Limitations:
- Circle occluder radii scale uniformly using
Math.min(scale.x, scale.y); non-uniformly scaled occluders will not cast elliptical shadows. - Darkness room rectangles do not have independent rotation (they only rotate with the camera).
- Polygon shadow volumes may split at corners if the silhouette edge is not face-on to the light.
- Circle occluder radii scale uniformly using
Overview of IsometricMap
TheIsometricMapis a specialized tile map in Excalibur that provides isometric rendering support. When configuring the map,tileWidthandtileHeightshould represent the height and width in pixels of the parallelogram base of the tile art asset, which may differ from the actual graphic pixel dimensions.Overview of built-in Excalibur Actions
Excalibur provides several pre-defined Action categories to modify Actor behavior and appearance:
- Movement Actions: Modify velocity and position over time. Includes
MoveBy,MoveTo,RotateTo,RotateBy,Meet,Follow,CurveBy, andCurveTo. - Cosmetic Actions: Change the visual appearance of an Actor. Includes
Blink,Flash,Fade, andScale. - Utility Actions: General purpose helpers including
Delay,CallMethod, andDie.
Caveat: Most actions end automatically upon completion. However,
Followis designed to never end automatically and must be stopped deliberately.Meetonly ends when it intersects the target, meaning it may also run indefinitely if the target is never reached.- Movement Actions: Modify velocity and position over time. Includes
Overview of EdgeCollider
TheEdgeCollideris a specialized collider used to create collisions with a single line segment. It inherits from theColliderclass.Overview of the ActionContext fluent API
TheActionContextclass allows developers to perform a sequence ofOverview of the Dual Tilemap Autotiling Technique
The Dual Tilemap technique solves common 2D autotiling problems like excessive art requirements and 'ambiguous tiles' (where a tile visually represents two different terrains). It separates the world into two distinct layers:
- World Tilemap (Logic): Manages game logic and states (e.g.,
soilvsgrass). It uses a single background tile. - Graphics/Mesh Tilemap (Overlay): An offset overlay that uses only 5 specific tiles (
Edge,InnerCorner,OuterCorner,Filled, andOpposite Corners). These tiles are rotated and stacked to create all necessary visual transitions.
This approach reduces the total asset count to 6 tiles (1 background + 5 overlay tiles) and ensures that walkable areas align perfectly with the logic map.
- World Tilemap (Logic): Manages game logic and states (e.g.,
Overview of ActionQueue in Excalibur.js
TheActionQueueclass represents an ordered sequence of actions for anActor. It is part of the Action API and is used to store and manage the list of actions to be executed. Actors implementActor.actions, which allows advanced users to manipulate the queue to adjust currently executing actions.Overview of SparseHashGridCollisionProcessor
TheSparseHashGridCollisionProcessoris a collision processor that uses a sparsely populated grid of uniform cells to bucket potential colliders. This spatial partitioning is used to efficiently detect collision pairs and collisions by limiting the number of checks to nearby objects.Overview of the ScreenElement class
TheScreenElementclass is a helperActorprimitive specifically optimized for drawing user interfaces (UIs). It is designed to be drawn on top of all other actors and does not participate in collisions, making it ideal for HUDs, menus, and other UI overlays.Overview of GraphicsComponent
TheGraphicsComponentis used to manage drawings for an entity in Excalibur.js. It is typically used in conjunction with a position component to determine where graphics are rendered in the game world.