Skip to content

Flambe core

Mark Knol edited this page Oct 18, 2017 · 29 revisions

Philosophy

Flambe mostly uses composition over inheritance. Flambe uses an entity/component system rather than sprawling inheritance hierarchies. The composition pattern also comes up repeatedly in other parts of Flambe's design.

How does the entity-component system work?

An entity is an object in a game. Entities don't do anything on their own, Components are attached to them to add data and logic. Entities are also hierarchical -- they can have other entities as children. This hierarchy when combined with the Sprite component, delivers the familiar Flash-like scene graph, but with the flexibility of being able to add other types of components.

Some components override each other if they have a common parent class. Adding a FillSprite to an entity for example will replace its ImageSprite. That's because they both extend Sprite. Since Sprite extends Component, anything that subclasses Sprite will share the "Sprite" namespace. Under the hood, this is implemented by giving a unique ID to each class that directly extends Component.

More info on entity/component system

Working with Entities and components can be confusing if you are used to OOP. There are better (non-Flambe) articles written by skilled developers about this workflow with entities and components. Some article describe slightly other implementations of the whole system; some even in other programming languages. It could give a bit more understanding about this interesting concept, but also about code organization and how to get familiar with it.

Wikipedia: Entity component system
Game Programming Patterns: Component
Evolve Your Hierarchy
T-Machine Entity Systems
Case study: Bomberman mechanics
Component-based engine design
What is an entity framework

Clone this wiki locally