| Crates.io | sdl2_particles |
| lib.rs | sdl2_particles |
| version | 0.3.1 |
| created_at | 2023-02-01 18:03:14.316758+00 |
| updated_at | 2025-02-06 19:59:51.405496+00 |
| description | Rust library made for creating particles using sdl2 |
| homepage | https://github.com/wiktorjanecki/sdl2_particles |
| repository | https://github.com/wiktorjanecki/sdl2_particles |
| max_upload_size | |
| id | 774030 |
| size | 8,078,768 |
Rust plug and play library for creating customizable particles with SDL2 context
Add crate to Cargo.toml and import everything at the beginning of your program:
use sdl2_particles::*;
Create a mutable particle state object and set its size (maximum number of particles):
let mut particles_state = ParticlesState::init(250);
Declare and customize ParticleType:
let emitting_type = ParticleTypeBuilder::new(16, 16, Duration::from_secs(2))
.with_color(random_color)
.with_effect(ParticleEffect::LinearMovement{velocity_x: random_velocity_x,velocity_y: -200.0})
.with_effect(ParticleEffect::LinearRotation{angular_velocity:60.0})
.with_effect(ParticleEffect::FadeOut{delay: Duration::from_secs_f32(1.0)})
.build();
Then initialize sdl2 window and context as you would do normally and create a game loop. Inside you must update and render and spawn your particles
loop {
particles_state.emit(5, &emitting_type, 400.0, 600.0);
particles_state.update(dt);
particles_state.render(&mut sdl_canvas);
}
More code and previews in examples/ folder