Skip to content

WiktorJanecki/sdl2_particles

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Particle Library for Rust SDL2 crate

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages