Smarter way to spawn meshes? #10052
Replies: 1 comment
-
Do you want to avoid passing the Do you have control over the impl Ball {
fn new(mass: f32, position: Vec2) -> Self { Ball { mass, position, velocity: Vec2::ZERO } }
fn mesh(&self) -> Mesh { /* .... */ }
fn matieral(&self) -> ColorMaterial { /* .... */ }
}
fn setup(mut cmds: Commands, mut meshes: ResMut<Assets<Mesh>>, mut mats: ResMut<Assets<ColorMaterial>>) {
commands.spawn(Camera2dBundle::default());
let ball = Ball::new(50., Vec2::ZERO);
let mesh = meshes.add(ball.mesh());
let material = mats.add(ball.material());
let bundle = MaterialMesh2dBundle { mesh, material, ..default() };
cmds.spawn((ball, bundle));
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello!
Currently I have setup a function that spawns a circle using this:
The problem begins when using the function. In my main script I have the setup function,
Is there any way for me to not have to specify commands, meshes and materials and only use the parameters that actually changes anything?
Beta Was this translation helpful? Give feedback.
All reactions