In my game, I have a CCSprite
that orbits another CCSprite
, much like an electron orbiting a nucleus. I have the electron as a child of the nucleus, to make animation much simpler. All I have to do is rotate the nucleus and the electron follows suite quite nicely.
However, my problem comes from wanting to have the orbit animation appear a little snazzier, by either adding something like a particle system trail, or a ribbon effect following the path of the electron. I cannot simply add a particle system to the electron itself, because the particles don't follow correctly, since they are being rotated by the nucleus as well. If I add the particle system to self
, then they appear correctly, but not in the same position as the object they are supposed to be trailing.
My question is this:
Is there a way to get the scene position of an object, say the electron, as opposed to only having access to it's position relative to it's parent?
Thanks.
Yes there is!
Each CCNode and its descendants has the ability to get a position relative to the scene:
CGPoint worldCoord = [mySprite convertToWorldSpace: mySprite.position];
This worldCoordinate will be relative to the scene as opposed to the parent node!
Hope this helped! ^_^
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With