#pixel-art #bevy #2d-game #camera #2d #pixel #pixel-perfect

bevy_tiled_camera

A camera for rendering low resolution pixel art in bevy

16 unstable releases (7 breaking)

0.9.0 Mar 17, 2024
0.8.0 Nov 5, 2023
0.7.0 Jul 12, 2023
0.6.0 Mar 8, 2023
0.2.4 Nov 22, 2021

#1475 in Game dev

Download history 142/week @ 2024-07-29 19/week @ 2024-08-05 9/week @ 2024-08-12 6/week @ 2024-08-19 24/week @ 2024-08-26 12/week @ 2024-09-02 7/week @ 2024-09-09 9/week @ 2024-09-16 64/week @ 2024-09-23 40/week @ 2024-09-30 6/week @ 2024-10-07 27/week @ 2024-10-14 7/week @ 2024-10-21 8/week @ 2024-10-28 38/week @ 2024-11-04

80 downloads per month
Used in 2 crates

MIT license

585KB
349 lines

License: MIT Crates.io docs

Bevy Tiled Camera

A camera for properly displaying low resolution pixel perfect 2D games in bevy. It works by adjusting the viewport to match a target resolution, which is defined by a tile count and the number of pixels per tile.

Example

use bevy_tiled_camera::*;
use bevy::prelude::*;

fn setup(mut commands:Commands) {
  // Sets up a camera to display 80 x 35 tiles.
  // Defaults to 8 pixels per tile with WorldSpace::Units.
  let camera_bundle = TiledCameraBundle::unit_cam([80,35]);
  commands.spawn(camera_bundle);
}
fn main() {
    App::new()
    .add_plugins((DefaultPlugins, TiledCameraPlugin))
    .add_systems(Startup, setup)
    .run();
}

World Space

Your world space defines how transforms and scaling is treated in your game. You either position everything in terms of world units, or in terms of pixels. The camera supports either via it's world_space functions.

Versions

bevy bevy_tiled_camera
0.13 0.9.0
0.12 0.8.0
0.11 0.7.0
0.10 0.6.0
0.9 0.5.0
0.8 0.4.0
0.6 0.3.0
0.5 0.2.4
0.5 0.2.3

Blurry sprites

By default bevy will create all new images with linear image sampling. This is good for smaller, high resolution images but causes severe blurriness with low resolution images. To fix it you can manually set the image sampler to nearest when creating your images, or change the default to always spawn new images with nearest sampling:

use bevy::prelude::*;
use bevy_tiled_camera::*;

App::new()
    .add_plugins((DefaultPlugins.set(ImagePlugin::default_nearest()), TiledCameraPlugin))
    .run();

Dependencies

~22–49MB
~793K SLoC