Crate bevy_map_runtime

Crate bevy_map_runtime 

Source
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.json files 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§

AnimatedSprite
Component for playing sprite animations
AnimatedSpriteHandle
Optional component for auto-loading animated sprites from a map project.
AnimationCustomEvent
Convenience event for custom payloads
AnimationDef
A single animation definition
AnimationParticleEvent
Convenience event for particle/VFX payloads
AnimationSoundEvent
Convenience event for sound payloads
AnimationTrigger
A one-shot animation trigger - fires once at a specific time
AnimationTriggerEvent
Event fired when an AnimationTrigger fires (one-shot)
AnimationTriggerRegistry
Registry for custom animation trigger types.
AnimationTriggered
Entity-scoped event fired when an animation trigger fires.
AnimationWindow
A duration-based animation window - has begin, tick, and end phases
AnimationWindowChanged
Entity-scoped event fired when an animation window changes phase.
AnimationWindowEvent
Event fired for AnimationWindow phase changes (duration-based)
AnimationWindowRegistry
Registry for custom animation window types.
DialogueChoice
A player choice option in a dialogue
DialogueChoiceEvent
Message sent when the player makes a choice
DialogueEndEvent
Message sent when a dialogue ends
DialogueHandle
Component that holds a handle to a dialogue tree asset
DialogueNode
A single node in the dialogue tree
DialogueRunner
Current state of an active dialogue
DialogueTree
A complete dialogue tree with nodes and connections
DialogueTreeHandle
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
MapLayerIndex
Component linking a tilemap layer to its source layer index
MapRoot
Marker component for the root entity of a spawned map
MapRuntimePlugin
Plugin for runtime map rendering
MapSpawnedEvent
Event emitted when a map has been spawned
RuntimeMap
Component marking a runtime map entity
SpawnMapEvent
Event to spawn a map from a Level
SpawnMapProjectEvent
Event to spawn a map from a MapProject with embedded tileset metadata
SpriteAnimationPlugin
Plugin for sprite animation support
SpriteData
Sprite data with spritesheet reference and animations
StartDialogueEvent
Message to start a dialogue (sent via MessageWriter, read via MessageReader)
TilesetTextures
Manages loaded tileset and sprite sheet textures for a map
WindowTracker
Tracks active animation windows for an entity

Enums§

DialogueNodeType
Type of dialogue node
LoopMode
Animation loop mode
TriggerPayload
Payload data for animation triggers and windows
WindowPhase
Phase of an animation window

Traits§

AnimationEventExt
Extension trait for registering animation trigger and window types.
AnimationTriggerType
Trait for types that can be animation triggers.
AnimationWindowType
Trait for types that can be animation windows.
MapCommandsExt
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