Crates.io | bevy_ecs_ldtk_default |
lib.rs | bevy_ecs_ldtk_default |
version | 0.1.1 |
source | src |
created_at | 2023-08-18 11:27:08.544928 |
updated_at | 2023-08-18 11:34:16.95278 |
description | Derive macros for bevy_ecs_ldtk that use bundle's Default impl instead of it's fields'. |
homepage | https://lib.rs/bevy_ecs_ldtk_default |
repository | https://github.com/elenakrittik/tartarus/tree/master/crates/bevy_ecs_ldtk_default |
max_upload_size | |
id | 947790 |
size | 17,833 |
bevy_ecs_ldtk_default
Derive macros for bevy_ecs_ldtk that use bundle's Default impl instead of it's fields'.
use bevy::prelude::*;
use bevy_rapier2d::prelude::*;
use bevy_ecs_ldtk::prelude::*;
use bevy_ecs_ldtk_default::*;
// Derive LdtkEntityDefault or LdtkIntCellDefault to make
// `bevy_ecs_ldtk` make use of your bundle's `Default` `impl`,
// instead of individual `Default` `impl`s of each of it's fields.
#[derive(Bundle, LdtkEntityDefault)]
pub struct PlayerBundle {
rigid_body: RigidBody,
}
impl Default for PlayerBundle {
fn default() -> Self {
// `PlayerBundle` now will spawn with kinematic rigid body.
Self { rigid_body: RigidBody::KinematicPositionBased }
// If we would've not used `LdtkEntityDefault` along with
// this `impl Default`, our `PlayerBundle` would've spawned
// with `rigid_body: RigidBody::Dynamic` (since that's what
// `impl Default` of `RigidBody` provides) instead, which is
// undesired.
}
}