Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/DisownedWheat/BabylonJS-Game-Logic-Examples
A collection of small projects that show possible ways of handling game logic with BabylonJS
https://github.com/DisownedWheat/BabylonJS-Game-Logic-Examples
babylonjs gamedev typescript
Last synced: 2 months ago
JSON representation
A collection of small projects that show possible ways of handling game logic with BabylonJS
- Host: GitHub
- URL: https://github.com/DisownedWheat/BabylonJS-Game-Logic-Examples
- Owner: DisownedWheat
- Created: 2020-05-05T21:55:48.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2024-04-22T20:30:40.000Z (9 months ago)
- Last Synced: 2024-08-01T13:36:52.084Z (5 months ago)
- Topics: babylonjs, gamedev, typescript
- Language: TypeScript
- Homepage:
- Size: 1.53 MB
- Stars: 28
- Watchers: 2
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-ccamel - DisownedWheat/BabylonJS-Game-Logic-Examples - A collection of small projects that show possible ways of handling game logic with BabylonJS (TypeScript)
- awesome-babylonjs - BabylonJS Typescript Logic Examples - A collection of small projects that show possible ways of handling game logic in a Babylon.js game. (Projects)
README
# BabylonJS Typescript Logic Examples
This repo is a collection of simple examples showing some ways of handling game logic within Babylon JS. This list is in no way exhaustive as Babylon is a very unopinionated framework.
These are also only my personal experiences so don't consider this an authoritative souce but more as an example to get you started on your own ideas.
## Building Examples
- Run `npm install`
- Run `npm buildX` where `X` is the number of the directory (1 is Inheritance, 2 is Behaviours & Observables, etc.)
- Run `npm buildAll` to build all examples
- Each example will have its output in its own `dist` directory# Observations
Please do note that these are my personal experiences and should in no way taken as gospel for or against these options.
## Inheritance
### Pros:
- Works well with how the Babylon project is structured
- Requires no external libraries
- Basic OOP makes it easy to learn
- Integrates well with Babylon scene tree
- Easy to debug### Cons:
- General problems with OOP inheritance model
- Have to write a lot of your own logic to keep references to game objects
- I just don't like it very much## Behaviours and Observables
### Pros:
- Integrates well with Babylon
- Requires no external libraries
- Very well thought out design
- Very flexible in how to handle your logic
- Easy to extend your own custom behaviours
- Flexible options with how observers are scoped and when they are called
- Very nice to work with in a typed language
- Easy to attach and remove behaviours
- Easy to debug### Cons:
- Somewhat boilerplate-y
- Querying objects for behaviours relies on strings which isn't quite as nice as querying class references
- Potential performance concerns (not that I've run into any performance issues with it yet but it would be easy to create poor-performing code with lots of closures in a behavior class)## ECS
### Pros:
- Very intuitive once you've wrapped your head around the pattern
- Apparently very performant
- Forced to organise code reasonably well
- Excellent separation of concerns
- Querying components based on class reference is nice when working with TS (this is particular to the `tick-knock` library)
- Easy to debug### Cons:
- Very boilerplate-y
- Takes a while to set up (but pays off massively on larger projects)
- Takes some time to adjust how to manage logic when working in a new paradigm
- Does not integrate with Babylon's scene tree very well (feels quite separate)## Event Based Architecture
### Pros:
- A lot of fun
- Entities are mostly completely separated and only communicate via an event bus which prevents tight coupling
- `nanoevents` library is a joy to use with TS
- Easier to integrate into Babylon's scene tree than ECS but has similar advantages
- Allows very rapid prototyping
- Can integrate cleanly with all other systems on this list### Cons:
- Harder to debug
- Requires some rethinking of control flow logic