-
Notifications
You must be signed in to change notification settings - Fork 6
Components
In Flambe, every component has 4 important functions:
-
onStart()
Called just before this component's first update after being added. This is the best place to put initialization logic that requires accessing other components/entities, since it waits until the rest of the entity hierarchy is accessible. Note that onStart may be delayed until the next frame after adding a component, depending on where in the update step it was added. -
onAdded()
Called after this component has been added to an entity.owner
is available after being added. The order of adding matters, in case you want to grab other components from the owner inside this function. -
onUpdate(deltaTime:Float)
Called when this component receives a game update. The deltatime is in seconds. -
onRemoved()
Called just before this component has been removed from its entity. -
dispose()
Removes this component from its owning entity. -
owner
The Entity this component is attached to (can be null).
It's very nice that the add function returns the owner entity. If you want to add a multiple components, this is how you could plug your features.
System.root.addChild(new Entity()
.add(new FillSprite(0x154d79, 100, 100))
.add(new Disposer())
.add(new CarEngine())
.add(new CarMover())
.add(new Path(myPath))
.add(new PathFollower())
.add(new SpeedAdjuster(1.0))
.add(new PowerupApplier())
.add(new Bot())
);
The onUpdate-function is called when this component receives a 'game' update, with delta time (The time elapsed since the last 'frame'). Flambe is framerate independent, but targeted at 60 FPS (frames per second). All animation/coded motion should be based on time using this delta time.
This dispose function removes this component from its owning entity. You should override the dispose-function in order to dispose objects yourself, to prevent memory leaks.
Documentation guide for Flambe - Targeted to version 4.0+
Flambe | Installation | Demo projects | Showcase | API Reference | Forum
Flambe is MIT licensed and available for free. Feel free to contribute!
- Home / Installation
- Entity / Components
- Core
- Assets
- Publish your game
- Other
- Editors
- Plugins, tools, extensions
- Help
- More Flambe