UpgradeAni.ts 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import { _decorator, Component, Node, tween, Vec3 } from 'cc';
  2. const { ccclass, property } = _decorator;
  3. /**
  4. * 升级面板动画控制器
  5. * 负责管理升级面板的显示和隐藏动画
  6. */
  7. @ccclass('UpgradeAni')
  8. export class UpgradeAni extends Component {
  9. /**
  10. * 显示面板动画
  11. * 面板从小到大的缩放动画,从屏幕中央弹出
  12. */
  13. public showPanel(): Promise<void> {
  14. return new Promise((resolve) => {
  15. // 设置初始状态:缩小到0,位置居中
  16. this.node.setScale(Vec3.ZERO);
  17. this.node.setPosition(0, 0, 0); // 确保面板在屏幕正中间
  18. this.node.active = true;
  19. // 缩放动画:从0放大到1
  20. tween(this.node)
  21. .to(0.3, { scale: new Vec3(1, 1, 1) }, {
  22. easing: 'backOut' // 使用回弹缓动效果
  23. })
  24. .call(() => {
  25. resolve();
  26. })
  27. .start();
  28. });
  29. }
  30. /**
  31. * 隐藏面板动画
  32. * 面板从大到小的缩放动画
  33. */
  34. public hidePanel(): Promise<void> {
  35. return new Promise((resolve) => {
  36. // 缩放动画:从1缩小到0
  37. tween(this.node)
  38. .to(0.2, { scale: Vec3.ZERO }, {
  39. easing: 'backIn' // 使用回弹缓动效果
  40. })
  41. .call(() => {
  42. this.node.active = false;
  43. resolve();
  44. })
  45. .start();
  46. });
  47. }
  48. /**
  49. * 立即隐藏面板(无动画)
  50. */
  51. public hidePanelImmediate(): void {
  52. this.node.setScale(Vec3.ZERO);
  53. this.node.active = false;
  54. }
  55. /**
  56. * 立即显示面板(无动画)
  57. */
  58. public showPanelImmediate(): void {
  59. this.node.setScale(Vec3.ONE);
  60. this.node.setPosition(0, 0, 0); // 确保面板在屏幕正中间
  61. this.node.active = true;
  62. }
  63. }