Tree.ts 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. import { _decorator, Component, Node, sp, Animation } from 'cc';
  2. const { ccclass, property } = _decorator;
  3. @ccclass('Tree')
  4. export class Tree extends Component {
  5. public animationComp: Animation | null = null;
  6. private fellCount: number = 0;
  7. start() {
  8. }
  9. playTreeAni()
  10. {
  11. this.scheduleOnce(() => {
  12. // tree shaking
  13. this.playShakeAnim();
  14. }, 0.5);
  15. //tree damage
  16. this.scheduleOnce(() => {
  17. this.playTreeDamageAni();
  18. }, 0.5);
  19. }
  20. playTreeDamageAni()
  21. {
  22. const role04Node = this.node.getChildByName('Game0001_tree');
  23. const spine = role04Node.getComponent(sp.Skeleton);
  24. switch (this.fellCount ) {
  25. case 0:
  26. {
  27. spine.setAnimation(0, 'idle2', false);
  28. }
  29. break;
  30. case 1:
  31. {
  32. spine.setAnimation(0, 'idle3', false);
  33. }
  34. break;
  35. case 2:
  36. {
  37. spine.setCompleteListener((trackEntry) => {
  38. // 判断是否是 click1 动画播放完成
  39. if (trackEntry.animation && trackEntry.animation.name === 'down') {
  40. // console.log('click1 动画播放完成');
  41. // 播放 idle1 循环动画
  42. spine.setAnimation(0, 'idle5', true);
  43. }
  44. });
  45. spine.setAnimation(0, 'down', false);
  46. }
  47. break;
  48. default:
  49. break;
  50. }
  51. this.fellCount++;
  52. }
  53. playShakeAnim() {
  54. // 获取Animation组件
  55. if (!this.animationComp) {
  56. this.animationComp = this.node.getComponent(Animation);
  57. }
  58. // 播放Shake动画
  59. if (this.animationComp) {
  60. this.animationComp.play('Shake');
  61. }
  62. }
  63. update(deltaTime: number) {
  64. }
  65. }