#gamedev #ecs #image #sprite #blitting

specs-blit

2D sprite rendering extension for the Specs ECS system

18 releases (4 breaking)

0.5.1 Apr 19, 2020
0.5.0 Apr 19, 2020
0.4.3 Apr 14, 2020
0.3.3 Mar 25, 2020
0.1.2 Dec 31, 2019

#55 in Images

Download history 27/week @ 2020-05-23 55/week @ 2020-05-30 17/week @ 2020-06-06 3/week @ 2020-06-13 2/week @ 2020-06-20 20/week @ 2020-06-27 22/week @ 2020-07-04 36/week @ 2020-07-11 31/week @ 2020-07-18 19/week @ 2020-07-25 20/week @ 2020-08-01 42/week @ 2020-08-08 41/week @ 2020-08-15 9/week @ 2020-08-22 24/week @ 2020-08-29 79/week @ 2020-09-05

399 downloads per month
Used in 2 crates

GPL-3.0 and AGPL-3.0-or-later

36KB
197 lines

specs-blit

2D sprite rendering extension for the Specs ECS system.

CI Version Rust Documentation License

All sprites are loaded onto a big array on the heap.

Example

// Setup the specs world
let mut world = specs::World::new();

// Load the blit components into the world
world.register::<specs_blit::Sprite>();

// 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 sprite_ref = {
    // Load the image using the image crate
    let img = image::open("examples/smiley.png")?;
    // Create a sprite from it
	const MASK_COLOR: u32 = 0xFF00FF;
    let sprite = blit::blit_buffer(&img, blit::Color::from_u32(MASK_COLOR));

    // Move the sprite to the render system with 4 rotations
    specs_blit::load(sprite, 4)?
};

// Create a new sprite entity in the ECS system
world.create_entity()
	.with(specs_blit::Sprite::new(sprite_ref))
	.build();

// Setup the dispatcher with the blit system
let mut dispatcher = specs::DispatcherBuilder::new()
	.with_thread_local(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())?;
}

Dependencies

~5MB
~103K SLoC