CocosCreator Spine动画的setEndListener() 有时候并不好用

public onKeyDown(event){
        switch(event.keyCode) {
            //点击空格
            case cc.KEY.space:
                this.spine.clearTracks();
                this.spine.setAnimation(0,"Boom",false);
                this.spine.setEndListener(()=>{
                    this.value++;
                    this.text.string=this.value.toString();
                });
                break;
        } 
    }

不知道是我不会用setEndListener(),还是就是不太用,当我点击空格时,第一次没反应,值不会增加,第二次动画播放之间就增加了,我的解决方法是,用setAnimationListener()方法

public onKeyDown(event){
        switch(event.keyCode) {
            case cc.KEY.space:
                this.spine.clearTracks();
                this.spine.setAnimation(0,"Boom",false);
                this.spine.setAnimationListener(this,            (skeletonNode,trackEntry,eventType,event,loop)=>{
                    //如果动画播放完了
                    if (eventType === sp.AnimationEventType.COMPLETE && trackEntry.animation) {
                        this.value++;
                        this.text.string=this.value.toString();
                    }
                });
                break;
        } 
    }

猜你喜欢

转载自blog.csdn.net/qq_25076715/article/details/86141017
今日推荐