叫我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 Error in check.length("fill") : 'gpar'成分'fill'的长度不能为零
  • ¥15 python:excel数据写入多个对应word文档
  • ¥60 全一数分解素因子和素数循环节位数
  • ¥15 ffmpeg如何安装到虚拟环境
  • ¥188 寻找能做王者评分提取的
  • ¥15 matlab用simulink求解一个二阶微分方程,要求截图
  • ¥30 乘子法解约束最优化问题的matlab代码文件,最好有matlab代码文件
  • ¥15 写论文,需要数据支撑
  • ¥15 identifier of an instance of 类 was altered from xx to xx错误
  • ¥100 反编译微信小游戏求指导