Closed guyguy2001 closed 1 month ago
If I'm already here, I'll add that I was confused by the color_material_to
name.
I started with sprite_color_to
based on the example, and when I tried to use the color material one, I just searched for material_color_to
, and didn't realize I was supposed to bring the "color" to the front.
I understand now that the role of the "color" in each name is different (in sprite it's the sprite's color, and in material it's the colors material), but that is still confusing if you don't come from this specific angle.
jeb.with(color_material(...));
jeb
is TargetComponent
ColorMaterial
interpolator is currently made to only interpolate using the target TargetAsset
. It seems like you're trying to interpolate by the Handle<ColorMaterial>
component which is not implemented (Unfortunately there is no compiler error for that now). You can create custom interpolator for that currently (Might also need custom system, @ me if you need any help). This is an interesting case I've never thought of before, it could be built-in.
For the naming I agree that it can be confusing 😅, I will add doc alias for discovery. When the function is created, I thought the name material_color
would be conflicting with other material types which might've the same property so that awkward name has been chosen. If you think otherwise, please tell me so!
I can't really say I understand the name collision on material_color
- I think I don't understand materials enough now to see what you mean.
As for my issue - I have this code now, which doesn't work for me: (Since this is probably a simple problem with my code, I dropped the reproduction code in favour of my real code)
pub fn spawn_sword(
parent: Entity,
// TODO: Role, take from laser's code
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<ColorMaterial>>,
mut commands: Commands,
) {
let starting_color = Color::WHITE.with_a(0.);
let color_material = materials.add(starting_color);
let material_backup = color_material.clone();
let mut color_animation = color_material.into_target().state(starting_color);
let size = 15.;
commands.entity(parent).with_children(|builder| {
// TODO: Improve the animation, make the sword only active for part of the animation
let sword = builder
.spawn((
SwordAttack::default(),
MaterialMesh2dBundle {
mesh: meshes.add(Circle::new(size)).into(),
material: material_backup,
..Default::default()
},
AnimationTarget,
Name::new("Sword animation"),
))
.animation()
.insert(sequence((
tween(
secs(0.1),
EaseFunction::CircularOut,
color_animation.with(interpolate::sprite_color_to(starting_color.with_a(1.0))),
),
tween(
secs(0.1),
EaseFunction::CircularIn,
color_animation.with(interpolate::sprite_color_to(starting_color.with_a(0.0))),
),
)))
.id();
});
}
color_animation
is TargetState<TargetAsset<ColorMaterial>, Color>
, which sounds promising to me.
The 2 suspicious things are:
clone
on the asset (I doubt the issue is there, but if you know how I can improve that I'd love to hear)AnimationTarget
as the component. Is that what's causing nothing to happen?material_color
collision naming is probably my overthinking. Though it'd be kept in this way until the overhaul.
Now for your issue.
interpolate::color_material_to
instead of sprite_color_to
. sprite_color_to
is only used with the Sprite
component.color_material.clone().into_target().state(starting_color)
instead.AnimationTarget
is only used with TargetComponent::Marker
and will not interact with anything else.This seems to work, thanks!
I'm surprised that color_material_to
doesn't give a compilation error, but other than that I think it makes sense to me
Closing this as resolved
I'm trying to use bevy_tween 0.5 with the
color_material
function, and it doesn't seem to animate the color. This also happened to me withcolor_material_to
, although it isn't in the repro.Reproduction
https://github.com/Multirious/bevy_tween/assets/6932278/c39847b3-137f-4d28-a1cf-9ad9e7711335 https://github.com/guyguy2001/bevy-tween-reproduction (The first commit is a working version copied from your
follow.rs
example, with 2 egui lines commented out; the second commit is me changing it from sprite to mesh2d and color materials)The difference from the example: (I don't know what's up with the weird
interpolate::color_material
import; moving it to the correct place doesn't fix it)Information
Windows 11, nightly-x86_64-pc-windows-msvc, rustc 1.79.0-nightly