| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- import { _decorator, Component, Node, sp, Animation } from 'cc';
- const { ccclass, property } = _decorator;
- @ccclass('Tree')
- export class Tree extends Component {
- public animationComp: Animation | null = null;
- private fellCount: number = 0;
- start() {
- }
- playTreeAni()
- {
- this.scheduleOnce(() => {
- // tree shaking
- this.playShakeAnim();
- }, 0.5);
-
- //tree damage
- this.scheduleOnce(() => {
- this.playTreeDamageAni();
- }, 0.5);
- }
- playTreeDamageAni()
- {
-
- const role04Node = this.node.getChildByName('Game0001_tree');
- const spine = role04Node.getComponent(sp.Skeleton);
- switch (this.fellCount ) {
- case 0:
- {
- spine.setAnimation(0, 'idle2', false);
- }
- break;
- case 1:
- {
- spine.setAnimation(0, 'idle3', false);
- }
- break;
- case 2:
- {
- spine.setCompleteListener((trackEntry) => {
- // 判断是否是 click1 动画播放完成
- if (trackEntry.animation && trackEntry.animation.name === 'down') {
- // console.log('click1 动画播放完成');
- // 播放 idle1 循环动画
- spine.setAnimation(0, 'idle5', true);
- }
- });
- spine.setAnimation(0, 'down', false);
- }
- break;
-
- default:
- break;
- }
-
- this.fellCount++;
- }
- playShakeAnim() {
- // 获取Animation组件
- if (!this.animationComp) {
- this.animationComp = this.node.getComponent(Animation);
- }
-
- // 播放Shake动画
- if (this.animationComp) {
- this.animationComp.play('Shake');
- }
- }
- update(deltaTime: number) {
-
- }
- }
|