pub trait Component: Lifecycle {
// Required methods
fn on_start(&mut self);
fn on_render(&self, draw_list: &mut DrawList, transform: &Transform2D);
fn on_destroy(&mut self);
fn name(&self) -> &str;
}Expand description
The base trait for all entity components.
Components encapsulate behavior that can be attached to an Entity.
The engine calls lifecycle methods at appropriate times during the scheduler loop.
Required Methods§
Sourcefn on_start(&mut self)
fn on_start(&mut self)
Called once when the component is first added to an active entity in a scene.
Sourcefn on_render(&self, draw_list: &mut DrawList, transform: &Transform2D)
fn on_render(&self, draw_list: &mut DrawList, transform: &Transform2D)
Called every render frame to record the component’s draw commands.
§Arguments
&mut DrawList- The draw list to record commands into.&Transform2D- The world-space transform of the owning entity.
Sourcefn on_destroy(&mut self)
fn on_destroy(&mut self)
Called once when the component is being removed or the entity is destroyed.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".