Expand description
Runtime map rendering via bevy_ecs_tilemap
This crate provides Bevy integration for loading and rendering maps created with bevy_map_editor using bevy_ecs_tilemap.
§Features
- Asset loader for
.map.jsonfiles with hot-reload support - bevy_ecs_tilemap-based GPU rendering
- Runtime terrain modification support via autotile integration
- Automatic entity spawning with derive macros
§Quick Start (Asset-Based Loading with Hot-Reload)
This is the recommended approach for most games:
ⓘ
use bevy::prelude::*;
use bevy_map_runtime::{MapRuntimePlugin, MapHandle};
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>) {
// Load map as a Bevy asset - supports hot-reload!
commands.spawn(MapHandle(asset_server.load("maps/level1.map.json")));
}To enable hot-reloading during development:
cargo run --features bevy/file_watcher§Manual Spawning (Advanced)
For more control over spawning:
ⓘ
use bevy::prelude::*;
use bevy_map_runtime::{MapRuntimePlugin, SpawnMapProjectEvent, TilesetTextures};
use bevy_map_core::MapProject;
fn load_map(
mut commands: Commands,
asset_server: Res<AssetServer>,
mut spawn_events: MessageWriter<SpawnMapProjectEvent>,
) {
let json = include_str!("../assets/maps/level1.map.json");
let project: MapProject = serde_json::from_str(json).unwrap();
let mut textures = TilesetTextures::new();
textures.load_from_project(&project, &asset_server);
spawn_events.send(SpawnMapProjectEvent {
project,
textures,
transform: Transform::default(),
});
}Re-exports§
pub use camera::clamp_camera_to_bounds;pub use camera::setup_camera_bounds_from_map;pub use camera::CameraBounds;pub use collision::MapCollider;pub use collision::MapCollisionPlugin;pub use entity_registry::attach_dialogues;pub use entity_registry::Dialogue;pub use entity_registry::EntityProperties;pub use entity_registry::EntityRegistry;pub use entity_registry::MapEntityExt;pub use entity_registry::MapEntityMarker;pub use entity_registry::MapEntityType;pub use loader::MapLoadError;pub use loader::MapProjectLoader;pub use render::complete_sprite_loads;pub use render::spawn_sprite_components;pub use render::SpriteSlot;pub use bevy_map_animation;pub use bevy_map_autotile;pub use bevy_map_core;pub use bevy_map_dialogue;
Modules§
- camera
- Camera bounds and utilities for map-based games
- collision
- Collision spawning systems for Avian physics integration
- entity_
registry - Entity registry for automatic entity spawning from map data
- loader
- Asset loader for MapProject files
- render
- Rendering utilities for runtime tilemaps
Structs§
- Animated
Sprite - Component for playing sprite animations
- Animated
Sprite Handle - Optional component for auto-loading animated sprites from a map project.
- Animation
Custom Event - Convenience event for custom payloads
- Animation
Def - A single animation definition
- Animation
Particle Event - Convenience event for particle/VFX payloads
- Animation
Sound Event - Convenience event for sound payloads
- Animation
Trigger - A one-shot animation trigger - fires once at a specific time
- Animation
Trigger Event - Event fired when an AnimationTrigger fires (one-shot)
- Animation
Trigger Registry - Registry for custom animation trigger types.
- Animation
Triggered - Entity-scoped event fired when an animation trigger fires.
- Animation
Window - A duration-based animation window - has begin, tick, and end phases
- Animation
Window Changed - Entity-scoped event fired when an animation window changes phase.
- Animation
Window Event - Event fired for AnimationWindow phase changes (duration-based)
- Animation
Window Registry - Registry for custom animation window types.
- Dialogue
Choice - A player choice option in a dialogue
- Dialogue
Choice Event - Message sent when the player makes a choice
- Dialogue
EndEvent - Message sent when a dialogue ends
- Dialogue
Handle - Component that holds a handle to a dialogue tree asset
- Dialogue
Node - A single node in the dialogue tree
- Dialogue
Runner - Current state of an active dialogue
- Dialogue
Tree - A complete dialogue tree with nodes and connections
- Dialogue
Tree Handle - Optional component for auto-loading dialogue trees from a map project.
- MapDialogues
- Resource storing all dialogue trees from the loaded map
- MapHandle
- Component for loading maps via the Bevy asset system
- MapLayer
Index - Component linking a tilemap layer to its source layer index
- MapRoot
- Marker component for the root entity of a spawned map
- MapRuntime
Plugin - Plugin for runtime map rendering
- MapSpawned
Event - Event emitted when a map has been spawned
- Runtime
Map - Component marking a runtime map entity
- Spawn
MapEvent - Event to spawn a map from a Level
- Spawn
MapProject Event - Event to spawn a map from a MapProject with embedded tileset metadata
- Sprite
Animation Plugin - Plugin for sprite animation support
- Sprite
Data - Sprite data with spritesheet reference and animations
- Start
Dialogue Event - Message to start a dialogue (sent via MessageWriter, read via MessageReader)
- Tileset
Textures - Manages loaded tileset and sprite sheet textures for a map
- Window
Tracker - Tracks active animation windows for an entity
Enums§
- Dialogue
Node Type - Type of dialogue node
- Loop
Mode - Animation loop mode
- Trigger
Payload - Payload data for animation triggers and windows
- Window
Phase - Phase of an animation window
Traits§
- Animation
Event Ext - Extension trait for registering animation trigger and window types.
- Animation
Trigger Type - Trait for types that can be animation triggers.
- Animation
Window Type - Trait for types that can be animation windows.
- MapCommands
Ext - Extension trait for spawning maps via commands
Functions§
- set_
tile - Update a tile at runtime
- spawn_
map - Spawn a map from a Level with the given tileset textures
- spawn_
map_ project - Spawn a map from a MapProject with proper tileset handling