2D
Draw 2D games with the NEO engine: sprites, sprite sheets, 2D meshes and shapes, text in the world, 2D cameras and tilemaps.
The NEO engine draws 2D scenes with the same entities, components and systems as 3D ones. A 2D scene is a Camera2d plus entities that carry something to draw: a Sprite, a Mesh2d with a material, a Text2d or a TilemapChunk. Each has a Transform, so you move, rotate and scale it like anything else.
2D rendering is part of the 2d profile, which NEO's builds turn on by default. It runs on every platform NEO supports, including the browser.
A minimal 2D scene#
use neo::prelude::*;
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_systems(Startup, setup)
.run();
}
fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
commands.spawn(Camera2d);
commands.spawn(Sprite::from_image(asset_server.load("branding/icon.png")));
}With the default 2D camera, one world unit is one logical pixel and the origin is the centre of the window. +X is right and +Y is up. Z orders entities: higher translation.z draws on top.
What draws in 2D#
| Component | What it is | Page |
|---|---|---|
Sprite | An image, a solid colour or a frame of a sprite sheet. | Sprites |
TextureAtlas | Picks one frame of a sprite sheet. | Texture atlases |
Mesh2d + MeshMaterial2d | A flat mesh (a circle, a polygon, your own) with a material. | 2D shapes and meshes |
Text2d | Text placed in the world. | Text in 2D |
Camera2d | An orthographic camera for 2D. | 2D cameras |
TilemapChunk | A grid of tiles drawn in one draw call. | Tilemaps |
For interface elements that follow the screen rather than the world, such as menus, health bars and buttons, use UI nodes instead.
Pages in this section#
- Sprites: images, tints, flipping, sizing, slicing and tiling.
- Texture atlases: sprite sheets, building atlases and frame animation.
- 2D shapes and meshes: primitives,
ColorMaterialand custom 2D materials. - Text in 2D:
Text2d, fonts, wrapping and anchors. - 2D cameras: projection, zoom, cursor to world and pixel-perfect rendering.
- Tilemaps:
TilemapChunkand per-tile data.