cocos creator 骨骼动画的使用

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/themagickeyjianan/article/details/85960867

1)导入骨骼动画

将JXM.png拖入到编辑器中,即可。 发现这个节点带了sp.Skeleton组件。

2)代码


cc.Class({
    extends: cc.Component,

    properties: {
        ske_anim: {
            type: sp.Skeleton,
            default: null
        }
    },

    // LIFE-CYCLE CALLBACKS:

    onLoad () {

        // 方法1: 节点查找
        // var spine = this.node.getChildByName("spine");
        // var ske_com = spine.getComponent(sp.Skeleton);

        // 方法2: 绑定方式
        var ske_com = this.ske_anim;


        this.ske_com = ske_com;
        this.ske_com = ske_com;

        //
        this.ske_com.setStartListener(function () {
            console.log("anim started");
        });

        this.ske_com.setEndListener(function () {
            console.log("anim end");
        });

        this.ske_com.setCompleteListener(function () {
            console.log("play once");
        });


    },

    enter_click: function(){
        this.ske_com.clearTrack(0);
        this.ske_com.setAnimation(0, "in", false);
        this.ske_com.addAnimation(0, "idle_1", false);
        this.ske_com.addAnimation(0, "in", false);
        this.ske_com.addAnimation(0, "idle_1", false);
    },

    anim_click: function(){
        this.ske_com.clearTrack(0);
        this.ske_com.setAnimation(0, "clk_1", false);
        this.ske_com.addAnimation(0, "idle_1", true);
    },

    start () {

    },

    // update (dt) {},
});

猜你喜欢

转载自blog.csdn.net/themagickeyjianan/article/details/85960867