求助,如果对象池中的对象有粒子特效,put以后会有残留粒子

我在对象池中put了20个雨滴,每一个雨滴上都有蓝色粒子特效,蓝色粒子特效能在0.5秒的时候播放完毕,产生粒子动画的两秒以后我才将雨滴put会对象池,但是重新生成的雨滴多多少少都会有一些灰色的粒子跟随在雨滴周围,不知道是什么原因,向大家求助一下
//开始时候初始化雨滴下落

initBullet_Rain_Start(){
    let bullet_Rain=this._Bullet_RainPool.get();
    if(!bullet_Rain){
        bullet_Rain=cc.instantiate(this.Bullet_RainPerfab);
    }
    //初始化雨滴一开始的位置
    // cc.loader.loadRes("RainBoom",cc.ParticleSystem,function(error,resource)
    // {
    //     if(error){
    //         cc.log(error);
    //     }
    //     if(bullet_Rain.children[1].getComponent(cc.ParticleSystem)===null)
    //     {
    //         bullet_Rain.children[1].addComponent(cc.ParticleSystem);
    //     }
    //     bullet_Rain.children[1].getComponent(cc.ParticleSystem).file=resource;
    // });
    //cc.log("file="+bullet_Rain.getComponent(cc.ParticleSystem).file);
    bullet_Rain.setPosition(cc.v2(this.Random(this.AllRain.getPosition().x,-cc.winSize.width/2),500));
    bullet_Rain.runAction(
        cc.sequence(
            //雨滴移动到下方
            cc.moveTo(3,bullet_Rain.getPosition().x,-250),
            cc.callFunc(()=>{
                //雨滴移动完成以后,大小变为0
                bullet_Rain.children[0].runAction(
                    cc.scaleTo(0.1,0),
                )
                //雨滴移动完成以后,开始粒子特效
                bullet_Rain.children[1].getComponent(cc.ParticleSystem).resetSystem();
                // cc.log(bullet_Rain.children[1].getComponent(cc.ParticleSystem).particleCount);
                // cc.log(bullet_Rain.children[1].getComponent(cc.ParticleSystem).stopped);
            },this),
            //延迟两秒
            cc.delayTime(2),
            cc.callFunc(()=>{
                //延迟两秒以后,恢复scale形状大小
                //cc.log(bullet_Rain.children[1].getComponent(cc.ParticleSystem).particleCount);
                cc.log(bullet_Rain.children[1].getComponent(cc.ParticleSystem).stopped);
                bullet_Rain.children[0].scaleX=0.5;
                bullet_Rain.children[0].scaleY=1;
                //延迟两秒以后,恢复形状大小
                //bullet_Rain.children[1].removeComponent(cc.ParticleSystem);
                this._Bullet_RainPool.put(bullet_Rain);
            },this)
        )
    );
    //将这个对象添加到这个脚本的子对象上
    this.node.addChild(bullet_Rain);
},

1赞

自顶一下

这个问题已修复,参考这个PR。
https://github.com/cocos-creator/engine/pull/4243

1赞

大佬,我的版本是2.0.9,照着修复完的代码在2.0.9的版本的对应文件中加上了这两行代码,这样做了以后还是会有残留。是不能修改源码还是说必须要下载最新的版本,刚入门不太了解,麻烦指教一下,谢谢。

升级到2.1.1应该是修复了,或者修改源码,请参考
https://docs.cocos.com/creator/manual/zh/advanced-topics/engine-customization.html#1-定制-javascript-引擎

1赞

感谢回复

楼主问题解决了么,遇到了跟你一样的问题

定制引擎,参考文档定制引擎部分,把源代码更新一下,https://github.com/cocos-creator/engine/pull/4243/files,也就是CCParticleSystem这个文件夹中加上两行代码
this.resetSystem();
this.stopSystem();
不能直接修改源码,要定制引擎

或者直接将游戏引擎更新到2.1.1

我们也遇到了,重置一下粒子就可以了、resetSystem

源代码代码加上去了,定制引擎也重新编译过了还是有残留。

这是我写的函数,我定制引擎以后就好了,按理说应该就没问题了,你检查一下你的代码

//开始时候初始化雨滴下落
initBullet_Rain_Start(){
    let bullet_Rain=this._Bullet_RainPool.get();
    if(!bullet_Rain){
        bullet_Rain=cc.instantiate(this.Bullet_RainPerfab);
    }
    //随机位置产生雨滴
    bullet_Rain.setPosition(cc.v2(this.Random(this._allRainPositionX+300,-this._width/2),500));
    bullet_Rain.runAction(
        cc.sequence(
            //雨滴移动到下方
            cc.moveTo(3,bullet_Rain.getPosition().x,-250).easing(cc.easeCircleActionIn()),
            cc.callFunc(()=>{
                //雨滴移动完成以后,大小变为0
                bullet_Rain.children[0].runAction(
                    cc.scaleTo(0.1,0),
                )
                //雨滴移动完成以后,开始粒子特效
                bullet_Rain.children[1].getComponent(cc.ParticleSystem).resetSystem();
            },this),
            //延迟两秒
            cc.delayTime(2),
            cc.callFunc(()=>{
                //延迟两秒以后,恢复scale形状大小
                bullet_Rain.children[0].scale=1;
                bullet_Rain.children[1].getComponent(cc.ParticleSystem).stopSystem();
                //延迟两秒以后,恢复形状大小
                this._Bullet_RainPool.put(bullet_Rain);
            },this)
        )
    );
    //将这个对象添加到这个脚本的子对象上
    this.node.addChild(bullet_Rain);
},

好的,我看看哪有问题。

2.4.2 的版本还有这个问题。 stopSystem resetSystem 也用。 你们有没有完全可用的 例子参考?

这个问题一直没有修复额

这个问题到现在没有修复,2.4.4从对象池取出上次放入的粒子,还是会在原来放入位置闪一下。resetSystem不管用

官方还打算改这个bug么?都拖了几年了

我也遇到了这个问题,还好我用的粒子对象不多,每次我都新见了粒子对象,旧对象销毁,避免了这个问题

stopSystem()之后,延时零点几秒put就可以解决残留问题

有用 :+1: