Actor/Costume Misalignment

Hi ya'll. Working on my first Box2DAS3 app and I have a misalignment between my costumes and my actors which seems to be caused by real number arithmetic tolerance errors. Here's a Cabin link to show you what I mean.

http://www.swfcabin.com/open/1263139802

Click in the game window to get the keystrokes registered, then use left and right arrows to rotate the maze...and the sprites become misaligned within one revolution. And they don't correct themselves when the direction of rotation is changed. Here's the relevant code:
Code:
package 
{
   import Box2D.Collision.Shapes.b2PolygonDef;
   import Box2D.Collision.Shapes.b2Shape;
   import Box2D.Collision.Shapes.b2ShapeDef;
   import Box2D.Common.Math.b2Vec2;
   import Box2D.Dynamics.b2Body;
   import fl.motion.MatrixTransformer;
   import flash.display.DisplayObjectContainer;
   import flash.geom.Matrix;
   import flash.display.Sprite;
   import flash.geom.Point;
   
   public class MazeActor extends Sprite
   {
      var costume:Sprite;
      var shape:b2Shape;
      
      var previousAngle:Number = 0.0;
               
      public function MazeActor(parent:DisplayObjectContainer, parentBody:b2Body, objectDefArray:Array)
      {
         var i:int = 0;
         var startPoint:Point = new Point();
         var obj:*;
         
         objectDefArray.reverse();
         
         var objectShapeDef:b2PolygonDef = new b2PolygonDef();
         objectShapeDef.density = 0.0;
         objectShapeDef.friction = 1.0;
         objectShapeDef.restitution = 1.0;
         
         graphics.beginFill(objectDefArray[0]);
         
         i = 0;
         do {
            obj = objectDefArray.pop();
            if (obj is Point)
            {
               b2Vec2(objectShapeDef.vertices[i]).Set(obj.x / Physical.RATIO,  obj.y / Physical.RATIO);
               if (i) graphics.lineTo(obj.x + 214.0, obj.y + 220.0);
               else
               {
                  startPoint = obj;
                  graphics.moveTo(obj.x + 214.0, obj.y + 220.0);
               }
            }
            else
            {
               graphics.lineTo(startPoint.x + 214.0, startPoint.y + 220.0);
               graphics.endFill();
            }
            
            i++;
               
         } while (obj is Point);
         
         objectShapeDef.vertexCount = i - 1;
         shape = parentBody.CreateShape(objectShapeDef);
         costume = this;
         parent.addChild(this);
      }
      
      public function Update(allMazeActors:Array, mazeBody:b2Body):void
      {
         UpdateCostume(mazeBody);
      }
      
      private function UpdateCostume(mazeBody:b2Body):void
      {
         var m:Matrix = this.transform.matrix;
         
         MatrixTransformer.rotateAroundExternalPoint(m, 214.0, 220.0, (mazeBody.GetAngle() - previousAngle) * 180.0 / Math.PI);
         this.transform.matrix = m;
         previousAngle = mazeBody.GetAngle();
      }
   }
}


I can't think of a solution to the misalignment...well, one solution....if I had the vertices of the b2Shapes I could redraw the sprites in the correct position every frame (although that seems excessively processor intensive as the maze gets more complex). Can I get those vertices from the b2Body's shapelist?

EDIT:Sorry about the work ya'll had to do because of the forum/wiki hacker!
You shouldn't update your sprite based on changes like that. What's wrong with simply setting the position and angle based on the bodies position and angle?
It is not a b2Body I am putting costumes on...it is the b2Shapes on the b2Body. That way I can rotate the b2Body (ie the maze). debugDraw knows where to draw the b2Shapes so I thought I could just get the data that way. You like the more traditional Actor Class with one body and one costume?

How would I recreate the effect using separate bodies for each shape in the maze?
You don't have to have only one actor per body... you could have an actor per shape and set them up in the local position relative to the body. You can do this during the creation of the shapes. Then, just like you attach a shape to a body, attach the actors to an actor container. Then, move that with the body and you're all set.
Yes, exactly. Shapes have no transformation of themselves - they are specified in body (local) co-ordinates. It doesn't matter if you have one or many sprites per body, you'll still find yourself applying the same transformation (the body transform) to each sprite to position it correctly.
But that is exactly what I was already doing (I thought), one MazeActor per shape on the mazeBody (see posted code). To update the costumes associated with those shapes I was using a matrix transform based on mazeBody.GetAngle() - previousAngle, however, the costumes were getting out of sync.

I ended up storing each vertex in the costume as a vector (storing the magnitude and angle), then calculating the new x & y for each vertex of the costume based on

vec.mag * Math.trigFunction(vec.angle + mazeBody.GetAngle()).

But I was looking for something less "loading" on the processor.

Code:
      private function UpdateCostume(mazeBody:b2Body):void
      {
         var i:int = 0;
         var bodyAngle:Number = mazeBody.GetAngle();
         var startX:Number = vertices[0].LENGTH * Math.cos(vertices[0].ANGLE + bodyAngle) + 214.0;
         var startY:Number = vertices[0].LENGTH * Math.sin(vertices[0].ANGLE + bodyAngle) + 220.0;
         
         graphics.clear();
         graphics.beginFill(kolor);
         graphics.moveTo(startX, startY);
         for (i = 1; i < vertices.length; i++)
         {
            graphics.lineTo(vertices[i].LENGTH * Math.cos(vertices[i].ANGLE + bodyAngle) + 214.0,
                        vertices[i].LENGTH * Math.sin(vertices[i].ANGLE + bodyAngle) + 220.0);
         }
         graphics.lineTo(startX, startY);
         graphics.endFill();
         
      }


Which, IMO, is more processor-intensive than MatrixTransform.rotateAroundExternalPoint().

EDIT:wait a sec...you're saying when I put the shapes on the mazeBody, also draw the shapes on a sprite whose origin is the same as the mazeBody. Then to update the costumes, rotate the sprite to agree with mazeBody.GetAngle()...oh wow....that was too easy....lol....I must need a break. Thanxs for the help!

EDIT EDIT: To anyone concerned...I followed the suggestion (placing all the costumes for the shapes on one Sprite and then just rotating the Sprite to agree with mazeBody.GetAngle()), however, the Sprite visually lagged behind the shapes on the mazeBody such that when I updated the costumes with this code
Code:
private function CheckKeys():void
      {
         if (leftArrow || rightArrow)
         {
            var currentPosition:b2Vec2 = mazeBody.GetPosition();
            var currentRotation:Number = mazeBody.GetAngle();
                        
            if (leftArrow) mazeBody.SetXForm(currentPosition, currentRotation -= 0.04);
            if (rightArrow)   mazeBody.SetXForm(currentPosition, currentRotation += 0.04);
            mazeSprite.rotation = mazeBody.GetAngle() * 180.0 / Math.PI;
         }
      }

the appearance on the screen was unsatisfactory (a ball bouncing around in the maze would penetrate the shapes drawn on the mazeSprite when the mazeSprite was rotating). The previous code (using an array of vertices, clearing and redrawing the costumes on the mazeSprite according to mazeBody.GetAngle) gave a much better appearance on the screen. Even though it would seem like a heck of a lot more code to execute than just setting a Sprites rotation = mazeBody.GetAngle(), in actuality both methods gave identical performance during gameplay with the second method giving a better visual appearance (the ball didn't penetrate the shapes even when the mazeSprite was rotating).

Original thread: https://box2d.org/forum/viewtopic.php?t=4265