Crates.io | bevy_tmx |
lib.rs | bevy_tmx |
version | 0.2.0 |
source | src |
created_at | 2021-06-05 11:12:50.581081 |
updated_at | 2021-10-25 17:53:44.676461 |
description | Scene loader for .tmx files created by the Tiled map editor |
homepage | |
repository | https://github.com/Kurble/bevy_tmx |
max_upload_size | |
id | 406438 |
size | 546,830 |
bevy_tmx is a plugin for the bevy game engine that allows you to read .tmx files from the tiled map editor as scenes. The plugin can be configured so that you can add more of your own components to the entities of the scene.
Currently, the tile maps being rendered are fairly simple, they are loaded as simple sprite entities, one per layer and sprite sheet.
RightDown
Using bevy_tmx is supposed to be really simple, just add the TmxPlugin
to your App
and load a scene.
If you need to add custom functionality to the entities loaded from the .tmx
file, you can customize the TmxLoader
to do so during load time.
use bevy::prelude::*;
use bevy::window::WindowMode;
use bevy_tmx::TmxPlugin;
struct PlayerComponent;
fn main() {
App::build()
.insert_resource(WindowDescriptor {
title: "Ortho".to_string(),
width: 1024.,
height: 720.,
vsync: false,
resizable: true,
mode: WindowMode::Windowed,
..Default::default()
})
.add_plugins(DefaultPlugins)
.add_plugin(TmxPlugin::default()
// Note that in tiled, the y axis points down, but in bevy it points up. The default scale is (1.0, -1.0).
.scale(Vec2::new(3.0, -3.0))
// This is the place to add more functionality to your objects
.visit_objects(|object, entity| {
if object.ty == "player" {
entity.insert(PlayerComponent);
}
})
)
.add_startup_system(spawn_scene.system())
.run()
}
fn spawn_scene(mut commands: Commands, asset_server: Res<AssetServer>) {
commands.spawn_scene(asset_server.load("ortho-map.tmx"));
commands.spawn().insert_bundle(OrthographicCameraBundle {
transform: Transform::from_xyz(600.0, -600.0, 50.0),
..OrthographicCameraBundle::new_2d()
});
}