Skip to content

A map/world/level editor for bevy games!

License

Apache-2.0 and 2 other licenses found

Licenses found

Apache-2.0
LICENSE-Apache-2.0
CC0-1.0
LICENSE-CC0-1.0
MIT
LICENSE-MIT
Notifications You must be signed in to change notification settings

jbuehler23/bevy_map_editor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

91 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

bevy_map_editor

A complete 2D tilemap editing ecosystem for Bevy 0.18. Create maps in the editor, load them at runtime with one line of code. For more complex asset loading, you can specify when to load those as well for more control.

Editor Screenshot

Headline

  • Visual Map Editor - egui-based editor with layer system, terrain painting, and entity placement
  • Project Management - Recent projects, preferences persistence, auto-open last project
  • Autotiling - Corner, Edge, and Mixed terrain modes using Wang tiles, currently WIP
  • Runtime Loading - Efficient tilemap rendering via bevy_ecs_tilemap 0.18
  • Custom Entities - Define game objects with #[derive(MapEntity)] proc macro
  • Sprite Animations - Define sprite sheets with named animations, autoloaded at runtime
  • Dialogue Trees - Visual node-based dialogue editor with branching conversations
  • Schema System - Type-safe entity properties with validation
  • Collision Shapes - Create and modify collision shapes on tiles, and integrate with avian2d automatically

Editor Features

Run Game & Live Editing

Launch your game directly from the editor and see changes in real-time:

  • Run Game button builds and launches your game project
  • Live editing - continue editing while the game runs
  • Auto-sync on save - press Ctrl+S to sync changes to the running game
  • Hot-reload - game automatically reloads the map via Bevy's asset watcher

Run Game Demo

Game Settings Dialog - Configure your game project path and starting level:

Game Settings

Tile Flipping

Flip tiles while painting for more variety:

  • X key - Toggle horizontal flip
  • Y key - Toggle vertical flip
  • Flip state shown in toolbar
  • Tiled-compatible flip flags in exported maps

Stamps (Tile Patterns)

Save and reuse tile patterns:

  • Ctrl+Shift+S - Create stamp from current selection
  • Stamps preserve tile arrangement and flip states
  • Quick access from Stamp Library panel

Terrain Painting

Autotile terrain transitions using Wang tiles (Corner, Edge, Mixed modes). This is heavily inspired by and credit to @bjorn for helping me with the Tiled autotiling algorithm!

Autotiling is still a WIP while I get the algorithm right, but you can manually paint Tiles in the map currently.

Here's the Tileset Editor: Tileset Editor/Terrain

The below video shows switching between corner/edge based autotiling and holding ctrl for full-tile autotiling

Autotiling

Entity Placement

Place custom entities with property editing in the inspector panel. As well as define custom Data Types for those entities.

Entity Screenshot

Demo of how easy it is to place/create Custom entities:

Entity Placement Demo

Dialogue Editor

Visual node-based dialogue tree editor with Text, Choice, Condition, and Action nodes. See example

Dialogue Editor

Spritesheet Editor

Define sprite sheets with multiple named animations per asset. See example. Load these spritesheets into animations, and use the Animation Editor for animation timelines/dopesheets!

Spritesheet loading: Spritesheet Editor

Animation Timeline with Trigger/Window events: Animation Editor

Collision Editor

Add Rectangle, Circle, and custom Polygon collision shapes to individual Tiles in the Tileset. You can then show these in the tilemap with the "Show Collisions" view

Collision Editor

Code Generation

Generate Rust code directly from your map data to accelerate game development.

Code Generation

Features:

  • Entity Structs - Auto-generate Bevy components from entity type definitions
  • Enum Definitions - Generate Rust enums from schema enum types
  • Behavior Stubs - Create placeholder functions for entity behaviors
  • Movement Systems - Generate input-driven movement code from Input profiles

Configure code generation in Game Settings, preview before writing, and open generated files directly in VS Code.

Code Preview

Crates

Crate Description
bevy_map Main crate - re-exports all runtime functionality
bevy_map_editor Visual map editor with egui UI
bevy_map_core Core data types (Level, Layer, Tileset, MapProject)
bevy_map_runtime Runtime rendering via bevy_ecs_tilemap
bevy_map_autotile Wang tile autotiling system - WIP
bevy_map_animation Sprite sheet animations
bevy_map_dialogue Dialogue tree system
bevy_map_derive #[derive(MapEntity)] proc macro
bevy_map_schema Entity property validation
bevy_map_codegen Rust code generation from map data

Quick Start

Install the Editor (Standalone Binary)

# From crates.io
cargo install bevy_map_editor

# Run the editor
bevy_map_editor

Embed in Your Project

use bevy::prelude::*;
use bevy_map_editor::EditorPlugin;

fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .add_plugins(EditorPlugin)
        .run();
}

Or run the example:

cargo run --example basic_editor -p bevy_map_editor_examples

Loading Maps at Runtime

Add bevy_map to your Cargo.toml:

[dependencies]
bevy = "0.18"
bevy_map = "0.1"

# With physics (Avian2D collisions)
# bevy_map = { version = "0.1", features = ["physics"] }
use bevy::prelude::*;
use bevy_map::prelude::*;

fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .add_plugins(MapRuntimePlugin)
        .add_systems(Startup, load_map)
        .run();
}

fn load_map(mut commands: Commands, asset_server: Res<AssetServer>) {
    commands.spawn(Camera2d);

    // Load and spawn the map
    commands.spawn(MapHandle(asset_server.load("maps/level1.map.json")));
}

Runtime Screenshot

Defining Custom Entities

Define game entities in code, place them in the editor:

use bevy::prelude::*;
use bevy_map::prelude::*;

#[derive(Component, MapEntity)]
#[map_entity(type_name = "NPC")]
pub struct Npc {
    #[map_prop]
    pub name: String,
    #[map_prop(default = 100)]
    pub health: i32,
}

fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .add_plugins(MapRuntimePlugin)
        .register_map_entity::<Npc>()
        .run();
}

Examples

Example Description
custom_editor Embed editor with custom configuration
runtime_loader Load and display a map
collision_demo Physics integration with Avian2D collisions and animations - START HERE
animation_auto_demo Auto-loading animated sprites
animation_manual_demo Manual sprite animation control
animation_triggers_demo Animation triggers and windows
dialogue_auto_demo Auto-loading dialogue trees
dialogue_manual_demo Manual dialogue handling
custom_entities_demo Custom entity types from map data
tileset_demo Tileset rendering and tile properties

Run examples:

cargo run --example custom_editor -p bevy_map_editor_examples
cargo run --example collision_demo -p bevy_map_editor_examples

Map File Format

Maps are saved as .map.json files see example full-project JSON:

{
  "version": 1,
  "schema": {
    "project": { "name": "My Game", "tile_size": 16 },
    "data_types": {
      "NPC": {
        "color": "#4CAF50",
        "placeable": true,
        "properties": [
          { "name": "name", "type": "string", "required": true },
          { "name": "health", "type": "int", "default": 100 }
        ]
      }
    }
  },
  "tilesets": [],
  "levels": [],
  "sprite_sheets": [],
  "dialogues": []
}

Keyboard Shortcuts

Shortcut Action
Ctrl+N New Project
Ctrl+O Open Project
Ctrl+S Save (+ sync if game running)
Ctrl+Shift+S Create Stamp from Selection
Ctrl+Z Undo
Ctrl+Y Redo
Ctrl+C/V/X Copy/Paste/Cut
G Toggle Grid
X Toggle Horizontal Flip
Y Toggle Vertical Flip
W Toggle World View
L Switch to Level View

Compatibility

Dependency Version
Bevy 0.18
bevy_ecs_tilemap 0.18
bevy_egui 0.39
Rust 1.76+

License

Licensed under either of:

Contributing

Contributions welcome! Please open an issue or submit a pull request.

About

A map/world/level editor for bevy games!

Resources

License

Apache-2.0 and 2 other licenses found

Licenses found

Apache-2.0
LICENSE-Apache-2.0
CC0-1.0
LICENSE-CC0-1.0
MIT
LICENSE-MIT

Contributing

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published

Languages