Entity Component System framework for Ebiten
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
2.2 KiB

Package gohan provides an Entity Component System framework for Ebiten.
An example game is available at /examples/twinstick which may be built by
executing the following command (in /examples/twinstick):
go build -tags example .
A general-purpose object, which consists of a unique ID, starting with 1.
The raw data for one aspect of an object, and how it interacts with the world.
Each component is assigned a unique ID, starting with 1.
Each system runs continuously, performing actions on every Entity that fits
each systems' set of required matching components.
Component Design Guidelines
Components are located in a separate package, typically named component. They
should be public (start with an uppercase letter) and may have any number of
publicly accessible data fields. They should not have any logic (i.e. game code)
within them, as all logic should be implemented within a System.
Rather than accessing components via Context.Component, using helper functions
(such as the following) helps to reduce code verbosity.
func Position(ctx *gohan.Context) *PositionComponent {
c, ok := ctx.Component(PositionComponentID).(*PositionComponent)
if !ok {
return nil
return c
System Design Guidelines
Systems are located in a separate package, typically named system. They should
be private (start with a lowercase letter) and offer an instantiation function
named as follows: NewSystemNameHere(). Data should be stored within components
attached to one or more entities, rather than within the systems themselves.
References to components must not be maintained outside each Update and Draw
call, or else the application will encounter race conditions.
Environment Variables
Running an application with the environment variable GOHAN_DEBUG set to 1
enables verification of Systems' access to Components. This verification is
disabled by default for performance reasons. While verification is enabled,
if a System attempts to access a Component which is not included in the
System's Needs or Uses, the application will panic and print information about
the illegal Component access. Setting GOHAN_DEBUG to 1 will also enable
printing System registration events and statistics.
package gohan