World (old) - Quillraven/Fleks GitHub Wiki

The core of Fleks is the World which is the container for entities, components, systems and families. It is the object that you need to update your systems.

To create a world simply call:

val world = world {}

A world without any system doesn't make sense and that's why there is a lambda argument for the world DSL function to configure it accordingly:

  • Use entityCapacity to set the expected maximum amount of entities. The default value is 512. The purpose of this property is to initialize internal collections and arrays with a proper size for your game to avoid a lot of Array.copy calls in the background which are slow.
  • Use systems to add a system to your world. The order of calls defines the order in which they are called when calling world.update.
  • Use components to register component listeners.
    • Note for KMP: components is also used to register components which is necessary for KMP because of missing reflection features of the JVM.
  • Use families to register family listener to your world.
  • Use injectables to register injectables for your systems, ComponentListener and FamilyListener.

Here is an example that creates a world for 1000 entities with two systems, one ComponentListener and one injectable:

JVM snippet

val w = world {
    entityCapacity = 1000

    injectables {
        add(b2dWorld)
    }

    systems {
        add<MoveSystem>()
        add<PhysicSystem>()
    }
    
    components {
        add<Box2dComponentListener>()
    }
}

KMP snippet

val w = world {
    entityCapacity = 1000

    injectables {
        add(b2dWorld)
    }

    systems {
        add(::MoveSystem)
        add(::PhysicSystem)
    }
    
    components {
        add(::MoveComponent)
        add(::Box2dComponent, ::Box2dComponentListener)
    }
}
⚠️ **GitHub.com Fallback** ⚠️