An event-based plugin for the Bevy game engine that provides a simple way to add a despawn effect for 2D sprites. Contains a basic physics implementation or a feature for bevy_rapier integration.

```rust use bevy::prelude::; use bevy_despawn_particles::prelude::;

[derive(Component, Default)]

pub struct Marker;

fn main() { App::new() .addplugins(DefaultPlugins) .addplugin(DespawnParticlesPlugin) .addsystem(setup.onstartup()) .add_system(despawn) .run(); }

fn setup(mut commands: Commands, assetserver: Res) { commands.spawn(Camera2dBundle::default()); commands .spawn(SpriteBundle { texture: assetserver.load("asteroid_round.png"), ..default() }) .insert(Marker); }

fn despawn( mut despawnparticleseventwriter: EventWriter, entities: Query>, ) { if let Ok(entity) = entities.getsingle() { despawnparticleseventwriter.send( DespawnParticlesEvent::builder() .withfade(true) // The particles will fade as they get closer to expiration .withshrink(true) // The particles will shrink as they get closer to expiration .withlinvel(150.0..300.0) // Random velocity between 150.0 and 300.0 .withangvel([-5.0, -2.5, 2.5, 5.0]) // Random angular velocity from the given list .withmass(1.0) // Always 1.0 .withlifetime(0.3..1.0) // Random lifetime between 0.3 and 1.0 .withangulardamping(1.0) // Always 1.0, angular 'friction' that decelerates the particle .withlinear_damping(1.0) // Always 1.0, linear 'friction' that decelerates the particle .build(entity), ); } }

```

Examples

All the following examples can be found in the examples directory of this repository.

| cargo run --release --example the_works| |:--:| | This example utilizes most of the parameters available. The particles fade and shrink, have a mass affected by gravity, shoot outwards and have some amount of angular velocity, and dampening. | |works|


| cargo run --release --example fade | |:--:| | In this example the particles are stationary and just fade, giving the visual effect of the entire sprite just fading away | |fade|


| cargo run --release --example shrink | |:--:| | In this example the particles are stationary and just shrink in place | |shrink|

| cargo run --release --example velocity | |:--:| | In this example the particles shoot outwards from the sprite | |velocity|

| cargo run --release --example mesh | |:--:| | Can be utilized on a Mesh. Also includes usage of the faux circle mesh to replace the arguably unappealing triangles that typically make up a Cirlcle mesh | |Screencast from 2023-07-19 20-55-22|