( 完美解决)spine在场景编辑器不能实时预览动作的问题

cocoscreator的场景编辑器是无法预览spine的,这让我们开发很麻烦,每次都得运行游戏

经过笔者的研究,查询spine源码,把eidtor的return去掉,但是发现spine可以预览,但是巨卡无比,经过多次研究,终于完美流畅解决

想了一下,也不是很难的东西,分享出来给大家

pr地址:
https://github.com/cocos-creator/engine/pull/7923/files
记得gulp build编译,pr还在审核能不能过,看各位大佬了,反正对游戏运行没有任何影响

效果图:
https://forum.cocos.org/uploads/default/original/3X/c/8/c865ddbdbf34de8e1066def128467b1c5d7d1d60.gif

23赞

mqffi-8nymi

animatingInEditMode这个你咋发现的。。搜了一下源码没搜到这个值

调试进去一步一步看

大佬能教下你这该怎么处理不?ccc萌新没干过这种操作

我按照你的pr改了一下,也build了,但是并没有生效,不知道什么原因 cocos版本2.4.4

if (CC_EDITOR) {
    // 重写update方法 达到在编辑模式下 自动播放动画的功能
    sp.Skeleton.prototype['update'] = function (dt) {
        if (CC_EDITOR) {
            cc['engine']._animatingInEditMode = 1;
            cc['engine'].animatingInEditMode = 1;
        }
        if (this.paused) return;

        dt *= this.timeScale * sp['timeScale'];

        if (this.isAnimationCached()) {

            // Cache mode and has animation queue.
            if (this._isAniComplete) {
                if (this._animationQueue.length === 0 && !this._headAniInfo) {
                    let frameCache = this._frameCache;
                    if (frameCache && frameCache.isInvalid()) {
                        frameCache.updateToFrame();
                        let frames = frameCache.frames;
                        this._curFrame = frames[frames.length - 1];
                    }
                    return;
                }
                if (!this._headAniInfo) {
                    this._headAniInfo = this._animationQueue.shift();
                }
                this._accTime += dt;
                if (this._accTime > this._headAniInfo.delay) {
                    let aniInfo = this._headAniInfo;
                    this._headAniInfo = null;
                    this.setAnimation(0, aniInfo.animationName, aniInfo.loop);
                }
                return;
            }

            this._updateCache(dt);
        } else {
            this._updateRealtime(dt);
        }
    }
}

把这段代码放在任意脚本里面就可以

9赞

dragon动画怎么在浏览器中预览啊?

这个不清楚… 我这个就是按照楼主那个pr修改的 只是这写不用重写build引擎而已…

直接放到脚本的update函数里吗

放任意脚本 不要在onload udpate函数里面 放在最外面

可以 多谢大哥

如何编译引擎看官方这里 https://docs.cocos.com/creator/manual/zh/advanced-topics/engine-customization.html?h=引擎

gulp build 后 用这个定制


2赞

感谢,先收藏,好麻烦啊

2.4.4版本可以使用,太牛了,开发起来太方便了,必须赞一个!!! :+1:

:+1: :+1: :+1:

SkeletonExt.js.zip (663 字节)

根据楼主的修改
写了个js 放入代码里(可以不用定制引擎),导入为插件,并开启允许编辑器加载即可 (2.4.4版本可用)

2赞

2.4.2报错:
image

操作:
image
每次切换pfefab都会提示这个错误

原理是这样的,把引擎里的代码拿来的,然后参照楼主的修改一下就可以了,你的报错可能是版本没对应上,你把对应的版本的引擎代码复制过来,替换一下 到 这个脚本里

不知道你是啥版本,这块咱是一样的,似乎不是这个问题

抱歉,上传错了。。换了一下,再试试 :joy:
SkeletonExt.js.zip (663 字节)

4赞