sdl2_particles

Crates.iosdl2_particles
lib.rssdl2_particles
version0.3.1
created_at2023-02-01 18:03:14.316758+00
updated_at2025-02-06 19:59:51.405496+00
descriptionRust library made for creating particles using sdl2
homepagehttps://github.com/wiktorjanecki/sdl2_particles
repositoryhttps://github.com/wiktorjanecki/sdl2_particles
max_upload_size
id774030
size8,078,768
Wiktor Janecki (WiktorJanecki)

documentation

README

SDL2 Particles

Crates.io Version docs.rs

Rust plug and play library for creating customizable particles with SDL2 context

Preview

Example

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

Commit count: 14

cargo fmt