[Using Problem] Unknown behavior after a tween
#52
-
the code demo is here
|
Beta Was this translation helpful? Give feedback.
Answered by
Multirious
Apr 6, 2025
Replies: 2 comments 3 replies
-
when out card observer pub fn out_card(
out: Trigger<Pointer<Out>>,
mut commands: Commands,
query: Query<&Parent>,
query_transform: Query<(&Transform, &Card), (Without<Dragging>, Without<Setted>)>,
) {
if let Ok(parent) = query.get(out.target) {
if let Ok((tr, card)) = query_transform.get(parent.get()) {
let target = AnimationTarget.into_target();
let mut start = target.transform_state(tr.clone());
info!("back");
info!("{:?}", tr.clone());
info!("{:?}", card);
commands.entity(parent.get()).animation().insert_tween_here(
Duration::from_secs_f32(1.1),
EaseKind::ExponentialOut,
start.translation_to(card.trans.translation),
);
}
}
} when dropdrap observer pub fn deal_on_drop(
drag_drop: Trigger<Pointer<DragDrop>>,
mut query: Query<&mut CaseZone>,
mut card_info_query: Query<&mut CardInfo>,
mut commands: Commands,
asset_server: Res<AssetServer>,
mut card_q: Query<&mut Card, Without<Setted>>,
mut p_q: Query<&Parent, With<CardInfo>>,
) {
// 场地的值? TODO 这处理
// info!("{:?}", drag_drop);
let case_zone = query.get_mut(drag_drop.target).unwrap();
let end = case_zone.clone().transform.translation;
// info!("{:?}", case_zone);
if let Ok(y) = card_info_query.get(drag_drop.dropped) {
// todo
}
//todo 处理内部的场地和卡片的关系
// info!("{:?}", y);
if let Ok(parent) = p_q.get(drag_drop.dropped) {
if let Ok(mut card) = card_q.get_mut(parent.get()) {
let p_clone = parent.get().clone();
// 设置卡片被放置了
let mut card_clone = card.clone();
let card_end = Card {
trans: Transform::from_translation(end.clone()),
};
spawn_ui_popup(
&mut commands,
&asset_server,
"是否登场?",
move |cmd, ch_q| {
let target = AnimationTarget.into_target();
let mut start = target.transform_state(card_clone.clone().trans);
// // todo 这里应该一系列动画
// card_clone.trans.translation = end.clone();
let mut mid = Vec3::ZERO;
mid.z = card_clone.trans.translation.z;
let mut mid2 = Vec3::ZERO;
mid2.z = card_clone.trans.translation.z + 3.0;
info!("{:?}", card_clone.clone().trans.translation);
info!("{:?}", mid);
info!("{:?}", end);
let mut mid_state = target.transform_state(Transform::from_translation(mid));
let mut mid_state2 = target.transform_state(Transform::from_translation(mid));
info!("add tween");
cmd.entity(p_clone)
.animation()
.insert(sequence((
tween(
Duration::from_secs_f32(1.0),
EaseKind::ExponentialOut,
start.translation_to(mid),
),
tween(
Duration::from_secs_f32(1.0),
EaseKind::ExponentialOut,
mid_state.translation_to(mid2),
),
tween(
Duration::from_secs_f32(0.6),
EaseKind::ExponentialOut,
mid_state2.translation_to(end),
),
parallel((event("boom"), event("shark"))),
)))
.insert(card_end.clone())
.insert(Setted);
// 恢复自由身体
if let Ok(children) = ch_q.get(p_clone) {
for child in children.iter() {
cmd.entity(child.clone()).remove::<PickingBehavior>();
}
}
info!("确认");
},
move |cmd| {
info!("取消");
},
);
}
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
-
after press A . card go to hand position. |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is caused by multiple conflicting tweens. There are animation that you have spawned but never removed and so the old animation fights with new one. One way to fix such issue is you can clean up old animation every time it finishes, like in this PR I've submitted for you.
You can learn the entity structure generated from
.animation()
method in this example..insert_tween_here
may work without having to clean up previous animation because the methods insert the components into existing entity and can replace previous ones whereas.insert
method will spawn a child everytime which will require some kind of management.It may not perfectly fit your use case so you can modify it however yo…