blit

A Rust library for blitting 2D sprites

CI Cargo License: GPL-3.0 Downloads

Documentation

Usage

Add this to your Cargo.toml:

toml [dependencies] blit = "0.7"

Demos

Smiley

Web: https://tversteeg.nl/blit/smiley/

Uses the ["image"] feature flag.

Displays the use of loading an image, blitting it fully and also blitting a subrectangle from it.

Local

console cargo run --example smiley

Aseprite Animation

Web: https://tversteeg.nl/blit/aseprite-animation/

Uses the ["image", "aseprite"] feature flags.

Displays the use of using the AnimationBuffer and Animation structs to create a simple time based animation.

Local

console cargo run --example aseprite-animation

Aseprite 9 Slice

Web: https://tversteeg.nl/blit/aseprite-9slice/

Uses the ["image", "aseprite"] feature flags.

Local

console cargo run --example aseprite-9slice

Example

Example Code

Uses the ["image"] feature flag:

toml [dependencies] blit = { version = "0.7", features = ["image"] }

```rust use blit::BlitExt;

const WIDTH: usize = 180; const HEIGHT: usize = 180; const MASK_COLOR: u32 = 0xFF00FF;

// The target buffer the image will be blit to let mut buffer: Vec = vec![0xFFFFFFFF; WIDTH * HEIGHT];

// Open the example image using the image crate let img = image::open("examples/smiley.png").unwrap().into_rgb8();

// Convert the image to a blit buffer let blitbuffer = imgrgb.toblitbuffer(Color::fromu32(MASKCOLOR));

// Blit the image twice to the buffer let pos = (10, 10); blitbuffer.blit(&mut buffer, WIDTH, pos); let pos = (20, 20); blitbuffer.blit(&mut buffer, WIDTH, pos); ```