Rotating a group of sprites - SOLVED

Apr 15, 2010 at 1:26 AM

I have run into a bit of a snag, and was hoping that you fine folks could help me out.


I have a group of sprites (each with their own geometry and rotations around their origin points) that I want to rotate as a group, around the groups origin.

What I would think to do is copy their geometry to a new body (for the group) using a positional and rotational offset, and rotate the new body... but that doesn't work :(


What should I do?



Apr 15, 2010 at 4:00 PM

Ok, I am going to give some more detail so I don't sound like a total noob.


I am creating an object builder (as part of my game's world builder) where you can add single sprites to a larger group to form a larger more complex object.


What I do is I add each sprite (with their own position and rotation about their origin point) to the group. I take the sprites geometry to create new geometry for the group using the offset position and rotation (with the offset rotation set to 0, because as I said in the post above that setting it to the rotation, or relative rotation doesn't have the desired effect) to make sure the geometry is in the right position. Then I can alter the groups position and rotation as I wish.

Unfortunately this didn't quite work out as the sprites rotation is updated based on it's geometry (so that it moves with the group), and the sprites original rotation is lost.

So I added a 'texture' rotation to the sprite, and when moving the geometry over to the new body, set the texture rotation to the sprites rotation so as to preserve the rotation that was lost.

This worked fine for the initial creation of the group, but when cloning the group, or editing the sprites within the group, things were a little cross-eyed. To fix it, I added the sprites rotation to the texture rotation and that worked for the editing of the sprites, but when cloning the group, it was over rotated... so to compensate, I used the rotation offset at -sprite.rotation... this worked for everything but loading the group in from a file...


so I think this pick at it till it works thing I was doing has lead me off the simple elegant solution I am sure exists... and I was hoping someone could help me find it.




Let me know if more explanation (or pictures) are needed.


Apr 15, 2010 at 4:31 PM

Ok, I have managed to get it working (mostly)... now my issue is with the contentTypeReader not Farseer...

Just in case anyone else runs into this...


My issue was that I was always increasing the textureRotation... What I should have been doing (and am doing now) is when cloning the sprite, set its rotation to the TotalRotation (rotation + textureRotation), and instead of using a -sprite rotation as the offset... using a -group rotation...


if it's not clear, and you want to know more... PM me. I'd be happy to help.

Apr 16, 2010 at 8:00 AM

You definitely don't have to use a separate body to make this work. In fact, if you

ever adopt 3.0, it'll be even trickier to do that.


I recommend you look into Matrices. Math with those is your easy solution, and it's

most likely better.



Apr 16, 2010 at 3:41 PM

No thats true, and if I were trying to simply select and rotate the group, I most likely wouldn't do what I did. And Farseer uses Matrix math for rotating attached geoms, so I could just look at what they do if I wanted to use that method.

But I am using a separate body for a couple reasons, not just to take advantage of Farseers math, but because I also want the individual sprites to act as a single object.

Thanks for the advice though.