Ejemplo n.º 1
0
        public static WorldSerializer SerializeWorld(World world, IWorldSerializer serializer)
        {
            WorldSerializer worldSerializer = new WorldSerializer(serializer);
            worldSerializer._world = world;

            foreach (var body in world.Bodies)
            {
                BodyDef def = new BodyDef();

                def.Active = body.IsActive;
                def.AllowSleep = body.IsSleepingAllowed;
                def.Angle = body.Angle;
                def.AngularDamping = body.AngularDamping;
                def.AngularVelocity = body.AngularVelocity;
                def.Awake = body.IsAwake;
                def.BodyType = body.BodyType;
                def.Bullet = body.IsBullet;
                def.FixedRotation = body.IsFixedRotation;
                //def.InertiaScale
                def.LinearDamping = body.LinearDamping;
                def.LinearVelocity = body.LinearVelocity;
                def.Position = body.Position;
                def.UserData = body.UserData;

                List<FixtureDef> fixtures = new List<FixtureDef>();

                foreach (var f in body.Fixtures)
                {
                    FixtureDef fixDef = new FixtureDef();
                    fixDef.Density = f.Density;
                    fixDef.Filter = f.FilterData;
                    fixDef.Friction = f.Friction;
                    fixDef.IsSensor = f.IsSensor;
                    fixDef.Restitution = f.Restitution;
                    fixDef.Shape = f.Shape;
                    fixDef.UserData = f.UserData;

                    fixtures.Add(fixDef);
                }

                worldSerializer.AddBody(body, def, fixtures);
            }

            return worldSerializer;
        }
Ejemplo n.º 2
0
 public WorldSerializer(IWorldSerializer serializer)
 {
     _serializer = serializer;
 }