#bevy #camera #pixel-perfect #2d #low-resolution

bevy_tiled_camera

A simple camera for properly displaying low resolution pixel perfect 2D games in bevy

5 releases

Uses new Rust 2021

0.2.4 Nov 22, 2021
0.2.3 Nov 22, 2021
0.2.2 Nov 22, 2021
0.2.1 Nov 21, 2021
0.2.0 Nov 21, 2021

#82 in Images

Download history 14/week @ 2021-11-15 84/week @ 2021-11-22

98 downloads per month
Used in bevy_ascii_terminal

MIT license

23KB
162 lines

License: MIT Crates.io docs

Bevy Tiled Camera

A simple camera for properly displaying low resolution pixel perfect 2D games in bevy.



This camera will scale up the viewport as much as possible while mainting your target resolution and avoiding pixel artifacts.

Example

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

fn setup(mut commands:Commands) {
  // Sets up a camera to display 80 x 25 tiles. The viewport will be scaled up
  // as much as possible to fit the window size and maintain the appearance of
  // 8 pixels per tile.
  let camera_bundle = TiledCameraBundle::new()
      .with_pixels_per_tile(8)
      .with_tile_count((80,25));

  commands.spawn_bundle(camera_bundle);
}

fn main() {
    App::build()
    .add_plugins(DefaultPlugins)
    .add_plugin(TiledCameraPlugin)
    .add_startup_system(setup.system())
    .run();
}

Note this is only half the work needed to avoid artifacts with low resolution pixel art. You also need to ensure the camera position and your sprite edges are aligned to the pixel grid.

You can change the camera settings at any time by adjusting the TiledProjection component on the camera entity.

World Space

Note that this projection assumes the size of one tile is equal to one world unit. This is different than Bevy's default 2D orthographic camera which assumes one pixel is equal to one world unit.

Versions

bevy bevy_tiled_camera
0.5 0.3
0.5 0.2

There is currently a bug in bevy version 0.5 where the camera projection does not update unless you actively resize the window.

Dependencies

~11–24MB
~384K SLoC

ߛa