use bevy::{prelude::*, sprite::Mesh2dHandle}; pub struct ParticleEffectPlugin; impl Plugin for ParticleEffectPlugin { fn build(&self, app: &mut App) { app .init_resource::() .insert_resource(PoolCount(1000)) .add_startup_system(particle_effect_startup); } } pub struct ParticleMesh { square: Mesh2dHandle, } impl FromWorld for ParticleMesh { fn from_world(world: &mut World) -> Self { let mut meshes = world.get_resource_mut::>().unwrap(); Self { square: meshes .add(Mesh::from(shape::Quad { size: Vec2 { x: 4.0, y: 4.0 }, flip: false, })) .into(), } } } pub struct PoolCount(usize); #[derive(Component)] pub struct ParticleComponent; fn particle_effect_startup( mut commands: Commands, particle_mesh: Res, pool_count: ResMut, mut materials: ResMut>, ) { for _p in 0 .. pool_count.0 { let color_mesh = ColorMesh2dBundle { mesh: particle_mesh.square.clone(), material: materials.add(ColorMaterial::from(Color::WHITE)), // default to invisible visibility: Visibility {is_visible: false}, ..default() }; commands .spawn_bundle(color_mesh) .insert(ParticleComponent); } }