叫我PT 2019-03-24 12:48 采纳率: 100%
浏览 911
已结题

学cocos在引入spine的示例的脚本中遇到一些困难,就是trackentry究竟是什么

在spine类下也没有找到相应的属性。。。但是函数列表却有。。。
而且示例脚本的函数有看不懂的地方,详见注释;

cc.Class({
extends: cc.Component,
editor: {
requireComponent: sp.Skeleton
},

properties: {
    mixTime: 0.2
},

onLoad () {
    var spine = this.spine = this.getComponent('sp.Skeleton');
    this._setMix('walk', 'run');
    this._setMix('run', 'jump');
    this._setMix('walk', 'jump');

    spine.setStartListener(trackEntry => {
        var animationName = trackEntry.animation ? trackEntry.animation.name : "";//就在这里!!!!  而且这整个函数是干嘛的我也不理解??
        cc.log("[track %s][animation %s] start.", trackEntry.trackIndex, animationName);
    });
    spine.setInterruptListener(trackEntry => {
        var animationName = trackEntry.animation ? trackEntry.animation.name : "";
        cc.log("[track %s][animation %s] interrupt.", trackEntry.trackIndex, animationName);
    });
    spine.setEndListener(trackEntry => {
        var animationName = trackEntry.animation ? trackEntry.animation.name : "";
        cc.log("[track %s][animation %s] end.", trackEntry.trackIndex, animationName);
    });
    spine.setDisposeListener(trackEntry => {
        var animationName = trackEntry.animation ? trackEntry.animation.name : "";
        cc.log("[track %s][animation %s] will be disposed.", trackEntry.trackIndex, animationName);
    });
    spine.setCompleteListener((trackEntry) => {
        var animationName = trackEntry.animation ? trackEntry.animation.name : "";
        if (animationName === 'shoot') {
            this.spine.clearTrack(1);
        }
        var loopCount = Math.floor(trackEntry.trackTime / trackEntry.animationEnd); 
        cc.log("[track %s][animation %s] complete: %s", trackEntry.trackIndex, animationName, loopCount);
    });
    spine.setEventListener((trackEntry, event) => {
        var animationName = trackEntry.animation ? trackEntry.animation.name : "";
        cc.log("[track %s][animation %s] event: %s, %s, %s, %s", trackEntry.trackIndex, animationName, event.data.name, event.intValue, event.floatValue, event.stringValue);
    });

    this._hasStop = false;
},

// OPTIONS

toggleDebugSlots () {
    this.spine.debugSlots = !this.spine.debugSlots;
},

toggleDebugBones () {
    this.spine.debugBones = !this.spine.debugBones;
},

toggleTimeScale () {
    if (this.spine.timeScale === 1.0) {
        this.spine.timeScale = 0.3;
    }
    else {
        this.spine.timeScale = 1.0;
    }
},

// ANIMATIONS

stop () {
    this.spine.clearTrack(0);
    this._hasStop = true;
},

walk () {
    this.spine.setAnimation(0, 'walk', true);
    this._hasStop = false;
},

run () {
    this.spine.setAnimation(0, 'run', true);
    this._hasStop = false;
},

jump () {
    var oldAnim = this.spine.animation;
    this.spine.setAnimation(0, 'jump', false);
    if (oldAnim && !this._hasStop) {
        this.spine.addAnimation(0, oldAnim === 'run' ? 'run' : 'walk', true, 0);
    }
},

shoot () {
    this.spine.setAnimation(1, 'shoot', false);
},

//

_setMix (anim1, anim2) {
    this.spine.setMix(anim1, anim2, this.mixTime);
    this.spine.setMix(anim2, anim1, this.mixTime);
}

});

  • 写回答

1条回答 默认 最新

  • devmiao 2019-03-24 14:30
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
  • ¥15 vs2019中数据导出问题
  • ¥20 云服务Linux系统TCP-MSS值修改?
  • ¥20 关于#单片机#的问题:项目:使用模拟iic与ov2640通讯环境:F407问题:读取的ID号总是0xff,自己调了调发现在读从机数据时,SDA线上并未有信号变化(语言-c语言)
  • ¥20 怎么在stm32门禁成品上增加查询记录功能
  • ¥15 Source insight编写代码后使用CCS5.2版本import之后,代码跳到注释行里面
  • ¥50 NT4.0系统 STOP:0X0000007B
  • ¥15 想问一下stata17中这段代码哪里有问题呀
  • ¥15 flink cdc无法实时同步mysql数据
  • ¥100 有人会搭建GPT-J-6B框架吗?有偿