
Build amazing 2D games for the web using Excalibur. For Free.
- Tweets264
- Following26
- Followers274
- Likes129
![Code Snippet ```typescript import { Graph } from 'excalibur'; // Create an empty graph of strings const graph = new Graph<string>(); // Add a few nodes with string data const nodeA = graph.addNode("A"); const nodeB = graph.addNode("B"); const nodeC = graph.addNode("C"); // Connect nodes with bidirectional edges (default) graph.addEdge(nodeA, nodeB); graph.addEdge(nodeB, nodeC); graph.addEdge(nodeC, nodeD); graph.addEdge(nodeD, nodeE); // Check if nodes are connected const connected = graph.areNodesConnected(nodeA, nodeB); // true // Get neighbors of a node const neighbors = graph.getNeighbors(nodeA); // [nodeB] // Find shortest path from A to C const { path, distance } = graph.shortestPathDijkstra(nodeA, nodeC); const aStarResults = graph.astar(nodeA, nodeB); ```](https://pbs.twimg.com/media/GudED44WEAAXkU1.jpg?name=small&format=webp)
ALT Code Snippet ```typescript import { Graph } from 'excalibur'; // Create an empty graph of strings const graph = new Graph<string>(); // Add a few nodes with string data const nodeA = graph.addNode("A"); const nodeB = graph.addNode("B"); const nodeC = graph.addNode("C"); // Connect nodes with bidirectional edges (default) graph.addEdge(nodeA, nodeB); graph.addEdge(nodeB, nodeC); graph.addEdge(nodeC, nodeD); graph.addEdge(nodeD, nodeE); // Check if nodes are connected const connected = graph.areNodesConnected(nodeA, nodeB); // true // Get neighbors of a node const neighbors = graph.getNeighbors(nodeA); // [nodeB] // Find shortest path from A to C const { path, distance } = graph.shortestPathDijkstra(nodeA, nodeC); const aStarResults = graph.astar(nodeA, nodeB); ```
![Code Snippet: ```typescript const query = new Query({ // all fields are optional components: { all: [ComponentA, ComponentB] as const, // important for type safety! any: [ComponentC, ComponentD] as const, // important for type safety! not: [ComponentE] }, tags: { all: ['tagA', 'tagB'], any: ['tagC', 'tagD'], not: ['tagE'] } }) ```](https://pbs.twimg.com/media/GudAUvxXkAAobnr.jpg?name=small&format=webp)
ALT Code Snippet: ```typescript const query = new Query({ // all fields are optional components: { all: [ComponentA, ComponentB] as const, // important for type safety! any: [ComponentC, ComponentD] as const, // important for type safety! not: [ComponentE] }, tags: { all: ['tagA', 'tagB'], any: ['tagC', 'tagD'], not: ['tagE'] } }) ```








