Changing particle system sprite frame on runtime

Hello,

I am trying to change the sprite frame of a particle system evenry 0.5 seconds.
Here is the code:

const {ccclass, property} = cc._decorator;

@ccclass
export default class ParticleFrames extends cc.Component {

@property(cc.SpriteAtlas)
atlas: cc.SpriteAtlas = null;

_time_passed: number = 0;
_current_frame_index: number = 0;

start () {

}


update (dt) {
    if (!this.atlas) {
        return;
    }

    this._time_passed += dt;

    if (this._time_passed >= 0.5) {
        this._current_frame_index++;
        if (this._current_frame_index > this.atlas.getSpriteFrames().length - 1) {
            this._current_frame_index = 0;
        }

        this.node.getComponent(cc.ParticleSystem).spriteFrame = this.atlas.getSpriteFrames()[this._current_frame_index];

        this._time_passed = 0;
    }
}

}

Some how, it does not work… any suggestions?

why don’t just create different nodes each with different particles (or particles with different sprites) and then just activate and deactivate them?

Handaling atlas is more simplier than handling multiple object nodes.
I prefer to change the sprite frame instead of creating more objects in the scene.

At the end of the day it should be acting as a particle sprite animation so each particle will be an animation.

ok…
well maybe try with this.node.getComponent(cc.ParticleSystem).resetSystem() after you change the sprite.
i

Hi hananht, I think I am achieving a similar effect as what you were working on. Would you mind sharing how you made it if you worked it out? Thank you sooo much :slight_smile:

I created a new particle system (similar to unity) to suit my needs. Now I can shoot nodes instead of frames. So I created a node with sprite sheet animation and when I shoot it I am activating a random clip.

Unfortunatly, I cannot share the code because I created it at my company. But I can send a video to show how it works it may help you to build one of your own…

Thank you for your response! If I understand you correctly, you create your own particle system using ts/js instead of using api in cocos, am I right? In that case, did you use any other framework to build it or you just wrote it straightly? This is super helpful. Thanks again.

You right. I did not used any 3rd party API. I wrote every thing by my self. I used unity 3d as a reference guide.

Sounds great. Many thanks!