-
Notifications
You must be signed in to change notification settings - Fork 26
Open
Description
I'm trying to use a spritesheet for one of the protos I'm working on and run into a sang with getting textureatlas
following this:
https://github.com/bevyengine/bevy/blob/latest/examples/2d/sprite_sheet.rs
and trying to merge the ideas from this example:
https://github.com/MrGVSV/bevy_proto/blob/main/examples/bundles.rs
I created this code:
#[typetag::serde]
impl ProtoComponent for EnemySprite {
fn insert_self(&self, commands: &mut ProtoCommands, _asset_server: &Res<AssetServer>) {
// === Get Prepared Assets === //
let texture: Handle<TextureAtlas> = commands
.get_handle(self, &self.texture_path)
.expect("Expected Image handle to have been created");
// === Generate Bundle === //
let my_bundle = SpriteSheetBundle {
texture_atlas:texture,
..default()
};
// === Insert Generated Bundle === //
commands.insert(my_bundle);
}
fn prepare(&self, world: &mut World, prototype: &dyn Prototypical, data: &mut ProtoData) {
// === Load Handles === //
let asset_server = world.get_resource::<AssetServer>().unwrap();
let handle:Handle<Image>= asset_server.load(self.texture_path.as_str());
let mut textureatlases = world.get_resource_mut::< Assets<TextureAtlas>>().unwrap();
let textureatlas = TextureAtlas::from_grid(handle,Vec2 { x: 24.0, y: 24.0 },4,1,None,None);
let texture_atlas_handle = textureatlases.add(textureatlas);
println!("Built Textureatlas for {:?}",texture_atlas_handle);
// === Save Handles === //
data.insert_handle(prototype, self, texture_atlas_handle);
}
However, get_handle
fails as it expects id to be an AssetPathId
is there anything I can do or is this unsupported in bevy_proto?
Thanks.
Metadata
Metadata
Assignees
Labels
No labels