#game #gamedev #bevy

bevy_particle_systems

A particle system plugin for Bevy

6 releases (breaking)

Uses new Rust 2021

0.5.0 Aug 2, 2022
0.4.1 Jun 16, 2022
0.3.0 Apr 27, 2022
0.2.0 Apr 7, 2022
0.1.0 Apr 6, 2022

#200 in Game dev

45 downloads per month

MIT license

9MB
675 lines

bevy_particle_systems


Crates.io docs MIT

A particle system plugin for bevy

Currently sprite based and focused on 2D.

Example

The above was captured running a release build of the basic example, cargo run --example basic --release, and ran at 140-150 FPS on a 2019 Intel i9 MacBook Pro, rendering about 10k particles.

INFO bevy diagnostic: frame_time                      :    0.006995s (avg 0.006966s)
INFO bevy diagnostic: fps                             :  142.956068  (avg 143.654887)
INFO bevy diagnostic: entity_count                    : 10132.000000  (avg 10149.350000)

Usage

  1. Add the [ParticleSystemPlugin] plugin.
use bevy::prelude::*;
use bevy_particle_systems::ParticleSystemPlugin;

fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .add_plugin(ParticleSystemPlugin::default()) // <-- Add the plugin
        // ...
        .add_startup_system(spawn_particle_system)
        .run();
}

fn spawn_particle_system() { /* ... */ }
  1. Spawn a particle system whenever necessary.
use bevy::prelude::*;
use bevy_particle_systems::*;

fn spawn_particle_system(mut commands: Commands, asset_server: Res<AssetServer>) {
    commands
    // Add the bundle specifying the particle system itself.
    .spawn_bundle(ParticleSystemBundle {
        particle_system: ParticleSystem {
            max_particles: 10_000,
            default_sprite: asset_server.load("my_particle.png"),
            spawn_rate_per_second: 25.0.into(),
            initial_velocity: JitteredValue::jittered(3.0, -1.0..1.0),
            lifetime: JitteredValue::jittered(8.0, -2.0..2.0),
            color: ColorOverTime::Gradient(Gradient::new(vec![
                ColorPoint::new(Color::WHITE, 0.0),
                ColorPoint::new(Color::rgba(0.0, 0.0, 1.0, 0.0), 1.0),
            ])),
            looping: true,
            system_duration_seconds: 10.0,
            ..ParticleSystem::default()
        },
        ..ParticleSystemBundle::default()
    })
    // Add the playing component so it starts playing. This can be added later as well.
    .insert(Playing);
}

Bevy Versions

bevy_particle_systems bevy
0.5 0.8
0.4 0.7

Dependencies

~18–27MB
~547K SLoC