bevy-toolbox
A simple crate that provides macros for simplifying some common Bevy tasks.
Table of Contents:
spawn!
This macro is used to simplify the entity creation of the bevy engine.
Spawner
Spawner is the object that have spawn
method which takes a bevy bundle and returns
EntityCommands
as the result.
Top level
Top level means the part of the macro thats been directly quoted by the macro itself.
spawn!
Entity definition
An entity definition is a tuple of components that will be spawned as an entity.
spawn!
Top level can accept multiple entity definitions.
spawn!
Order
The order of any bit in the macro matters. The execution order is strictly follow the macro input.
// entity `a` will always being spawned before `b`
spawn!
Naming
An entity can be named for later reference. The variable will hold the Entity
of the corresponding
entity, NOT THE EntityCommands
.
spawn!
Parenting
A top level entities can have explicit parent. Parenting is done by using >
operator.
spawn!
Insertion
Insertion is a way to add some components to an existing entity. The entity must be named and spawned in advanced in order to be referenced.
spawn!
Code block injection
Since the entities inside the macro is enclosed within a generated scope to prevent the namespace pollution, code block injection makes it possible to execute code without leaving the macro.
spawn!
Extension
An entity can be extended with any number of:
- Children Group
- Method Call
- Code Block
All extensions are started with .
after the entity definition.
Children Group
Children group is a group of entities that will be spawned as children of the parent entity. We
use []
to define a new children group. A children group can have multiple entities. Within the
same group, the entities can reference each other, but entities in 2 different groups under same
parent can't.
spawn!
Method Call
Method call is a call to a method of EntityCommands
. The auto completion is supported for the
method name and the arguments.
spawn!
Since observe
is most likely to be used, a shortcut is provided to omit the method name.
spawn!
To reference the current entity, you can use this
for Entity
and entity
for EntityCommands
.
spawn!
Code Block
Code block is a block of code that will be executed in the context of the entity. As previously
mentioned, the code block can also access this
and entity
variables.
spawn!