2D sprite rendering extension for the Specs ECS system.
All sprites are loaded onto a big array on the heap.
```rust // Setup the specs world let mut world = specs::World::new();
// Load the blit components into the world
world.register::
// Add the pixel buffer as a resource so it can be accessed from the RenderSystem later const WIDTH: usize = 800; const HEIGHT: usize = 600; world.insert(specs_blit::PixelBuffer::new(WIDTH, HEIGHT));
let spriteref = { // Load the image using the image crate let img = image::open("examples/smiley.png")?; // Create a sprite from it const MASKCOLOR: u32 = 0xFF00FF; let sprite = blit::blitbuffer(&img, blit::Color::fromu32(MASK_COLOR));
// Move the sprite to the render system
specs_blit::load(sprite)?
};
// Create a new sprite entity in the ECS system world.createentity() .with(specsblit::Sprite::new(sprite_ref)) .build();
// Setup the dispatcher with the blit system let mut dispatcher = specs::DispatcherBuilder::new() .withthreadlocal(specs_blit::RenderSystem) .build();
// Enter the render loop that should be called every frame while render_frame() { // Update specs dispatcher.dispatch(&mut world);
// Add/remove entities added in dispatch through `LazyUpdate`
world.maintain();
// Get the pixel buffer resource to render it
let buffer = world.read_resource::<specs_blit::PixelBuffer>();
// Render the pixel buffer
window.update_with_buffer(&buffer.pixels(), buffer.width(), buffer.height())?;
} ```