Position particles on sprite while moving

guys,
I need help with this… its driving me nuts…
I need to position particles on the back of my sprite. My sprite is spaceship and the particles is the engine firetail. So, when the spaceship moves around the particles have to move too.
I’m having problems to come up with the right code to always get the right position.

          //this is the spaceship
          Point normalized = targetPoint - this->getPosition();
                normalized = normalized.normalize();

                float angle = CC_RADIANS_TO_DEGREES(atan2f(normalized.y, -normalized.x)) + 270;
                Point desiredPosition = this->getPosition() + ( normalized * m_moveSpeed) ;

                this->setPosition(desiredPosition);
                this->setRotation(angle);
                
                int x=0;
                int y=0;
                //trying to make the particles to follow the spaceship.. not working properly.
                if(angle > 180  && angle < 270){
                    x= desiredPosition.x;
                    y= desiredPosition.y+40;
                }else if(angle > 270  && angle < 360){
                    x= desiredPosition.x-40;
                    y= desiredPosition.y+40;
                }else if(angle > 0  && angle < 90){
                    x= desiredPosition.x+40;
                    y= desiredPosition.y+40;
                }else if(angle > 90  && angle < 180){
                    x= desiredPosition.x+40;
                    y= desiredPosition.y+40;
                }
                m_engine1->setPosition( Point(x,y) );
                m_engine1->setRotation(angle);

any help will be appreciated… tkx

you can try different particle position mode

    enum class PositionType
    {
        /** Living particles are attached to the world and are unaffected by emitter repositioning. */
        FREE,
        
        /** Living particles are attached to the world but will follow the emitter repositioning.
         Use case: Attach an emitter to an sprite, and you want that the emitter follows the sprite.
         */
        RELATIVE,
        
        /** Living particles are attached to the emitter and are translated along with it. */
        GROUPED,
    };
2 Likes

Thank you Wuhao!
I forgot post the particle creation code. I’m setting the PositionType to GROUPED… I’ll try with RELATIVE.
However, I’m not use the particles at all because my FPS is going down fast from 60FPS to 9FPS, because I believe I have too many particles on screen. In average I’ve 20 spaceships on the screen at some point and each of them will have at least 2 particles emitters, one for each engine.