Systems
Systems are just plain functions that can specify dependencies to be injected at runtime. Dependencies can either be Queries or Resources.
There are 2 types of Systems, System
and SystemOnce
, and you may use the return type of the function to declare which type it is.
import type { System, SystemOnce } from '@vaguevoid/fiasco'
function animalsInit(): SystemOnce {
// runs only once
}
function animalsMove(): System {
// runs every frame
}
// Magic export - must be named `systems`
export const systems = [animalsInit, animalsMove]
IMPORTANT
Be sure to export your systems using the magic export systems
from the root of the game - the order of the array matters, systems run in that order.
INFO
The return type for systems is optional and defaults to System
, so only SystemOnce
systems really need to specify the return type. But it's up to you.
System arguments must only be Queries or Resources:
function mySystem(query: Query<[...]>, frame: FrameConstants, aspect: Aspect) {
// update items
}
Systems can be enabled or disabled with setSystemEnabled
. A disabled system will no longer run every frame until re-enabled.
function system1() {
// disable system2
engine.setSystemEnabled("system2", false)
}