| Crates.io | bevy_rpack |
| lib.rs | bevy_rpack |
| version | 0.2.0 |
| created_at | 2025-01-14 13:13:06.176043+00 |
| updated_at | 2025-05-07 09:03:47.780454+00 |
| description | Bevy plugin with rpack atlas support |
| homepage | https://github.com/Leinnan/rpack |
| repository | https://github.com/Leinnan/rpack.git |
| max_upload_size | |
| id | 1515956 |
| size | 123,265 |
A Bevy plugin with support for the rpack.json atlases.
Generating a rpack atlas can be done in two ways:
rpack_egui application at itch.io. Just drop in files into program, specify settings and it should be possible to download both the json and image file for atlas.rpack_cli CLI tool as described below.First install the tool:
cargo install rpack_cli
Guide assumptions:
tiles directory of the Bevy project.assets directory.In order to generate a tilemap execute this command:
rpack_cli generate --source-paths "tiles/**/*" --size 1024 assets/game_tilemap
It is also possible to generate a config file for rpack_cli and then use it to generate a tilemaps:
rpack_cli config-create --source-paths "tiles/**/*" --size 1024 --output-path assets/tilemap tiles_config
rpack_cli tiles_config.rpack_gen.json
Both ways result in creation of two files:
assets/tilemap.png containing atlas imageassets/tilemap.rpack.json containing atlas image frames data used by bevy plugin.Second way generated additional tiles_config.rpack_gen.json file that provides settings for the CLI tool.
With those files generated it should be possible to use atlases like in the example from Example docs section.
Since rpack_cli is a rust library it can be called easily from Bevy application.
It can be useful for building special version of the game for artists in the team so they can run the game and be sure that they don't forget to rebuild atlases after doing changes in graphics.
In order to achieve that add this dependency to the project:
rpack_cli = "0.1"
Then in main.rs just before App::new() add something like this:
rpack_cli::TilemapGenerationConfig::read_from_file("example_config.rpack_gen.json")
.expect("Failed to read config")
.generate()
.expect("Failed to generate tilemap");
Then on each run of the game it will regenerate the atlas before running the game.
Disclaimer: It should be used carefully and in most cases be called only in development builds on desktop platforms.
use bevy::prelude::*;
use bevy_rpack::prelude::*;
#[allow(dead_code)]
#[derive(Resource)]
struct Holder(pub Handle<RpackAtlasAsset>);
fn main() {
App::new()
.add_plugins((DefaultPlugins, RpackAssetPlugin))
.add_systems(Startup, setup)
.add_systems(Update, atlas_loaded)
.run();
}
fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
commands.insert_resource(Holder(asset_server.load("tilemap.rpack.json")));
commands.spawn(Camera2d);
}
fn atlas_loaded(
mut ev_asset: EventReader<AssetEvent<RpackAtlasAsset>>,
atlases: RpackAtlases,
mut commands: Commands,
) {
if !ev_asset
.read()
.any(|ev| matches!(ev, AssetEvent::LoadedWithDependencies { id: _ }))
{
return;
}
if let Ok(sprite) = atlases.try_make_sprite("agents/spaceAstronauts_005") {
commands.spawn(sprite);
};
if let Ok(image_node) = atlases.try_make_image_node("agents/spaceShips_006") {
commands.spawn(image_node);
}
}
bevy_rpack is dual-licensed under MIT and Apache 2.0 at your option.
| Bevy version | Crate version |
|---|---|
| 0.16 | 0.2 |
| 0.15 | 0.1 |