animation_utils.ts 666 B

12345678910111213141516171819
  1. import { _decorator, Node, tween, v3, Vec3, Tween, UIRenderer } from 'cc';
  2. const { ccclass, property } = _decorator;
  3. /**
  4. * 弹窗动画 - 使用弹性缓动效果实现弹窗出现的动画
  5. * @param node 要应用动画的节点
  6. * @param endScale 最终缩放比例,默认为1.0
  7. * @param duration 动画持续时间,默认为1.2秒
  8. * @param callback 动画完成后的回调函数
  9. */
  10. export function ani_ui(node: Node, end: number = 1.0): void {
  11. Tween.stopAllByTarget(node); // 打断旧动画
  12. //重置scale
  13. node.setScale(0.5, 0.5, 1);
  14. tween(node)
  15. .to(1.2, { scale: v3(end, end, 1) }, { easing: 'elasticOut' })
  16. .start();
  17. }