| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- import { _decorator, Component, Node, sp } from 'cc';
- const { ccclass, property } = _decorator;
- @ccclass('Charactor')
- export class Charactor extends Component {
- // 砍树计数器
- private fellCount: number = 0;
- start() {
- }
- playFellTreeAni()
- {
- // 1. 找到子节点 role_04
- const role04Node = this.node.getChildByName('role_04');
- if (!role04Node) {
- console.error('未找到 role_04 节点');
- return;
- }
- // 2. 获取 Spine 组件
- const spine = role04Node.getComponent(sp.Skeleton);
- if (!spine) {
- console.error('role_04 节点上没有 Spine 组件');
- return;
- }
- // 3. 设置动画完成监听器
- spine.setCompleteListener((trackEntry) => {
- // 判断是否是 click1 动画播放完成
- if (trackEntry.animation && trackEntry.animation.name === 'click') {
- // console.log('click1 动画播放完成');
- // 播放 idle1 循环动画
- spine.setAnimation(0, 'idle', true);
- }
- });
- // 4. 播放动画 click1,只播放一次
- spine.setAnimation(0, 'click', false);
- }
- update(deltaTime: number) {
-
- }
- }
|