cocos2d-iphonerotationccspriteccparticlesystem

Rotating CCSprite with CCParticleSystemQuad as child node


I have a CCSprite that can bounce around the iPhone's screen. This sprite has a CCParticleSystemQuad as a child node. The particles are just small, simple circles that trail behind the moving sprite. Everything works fine until the sprite rotates due to collision with a screen edge. When this happens the existing particles are suddenly drawn in a strange location.

Any idea why this is happening?

I've tried a few things so far. First I tried all three positionType values for the particle system. None of these fixed the rotating problem. The actual rotation is done with a CCRotateTo. Removing this action fixes the particle location problem. So perhaps rotating a CCSprite child node on a CCLayer could replace my current CCSprite. I tried reading through http://www.cocos2d-iphone.org/forum/topic/63951 but it's a bit over my head. Any feedback and suggestions are greatly appreciated!

Edit #1 I found a quick fix: immediately before the CCRotateTo I tell the trailing particles to resetSystem. However I'd still like to understand the cause of the odd drawing behavior.


Solution

  • I think this is happening because of the CCParticleSystem being a child of the CCSprite, then any position or rotation that you do on the sprite will affect the behavior of all the particles that are being and have already been emitted. So if you have some trailing particles that are still lingering on screen, they are still children of the CCSprite, and rotating it will cause all of the lingering particles to rotate around the sprite's current position.

    If you want to eliminate this effect, you could add the CCParticleSystem to the layer, so that it will be unaffected by the CCSprite's rotation. The downside to this approach is that you will have to add code to have the CCParticleSystem track the position of the CCSprite since it is no longer a child of the CCSprite. That should be pretty easy to do however.