Example #1
0
        public BodyNode(WorldObject world, BodyDefSerialized x)
            : base(x.Name, 3)
        {
            Body = x.Body;
            Name = x.Name;

            for (int i = 0; i < x.FixtureIDs.Count; ++i)
            {
                var fixture = world.Fixtures[x.FixtureIDs[i]];
                _fixtures.Add(fixture);
            }

            _mass = Body.ComputeMass(OnlyFixtures);

            _fixtures.ObjectsAdded += new EventHandler(_fixtures_ObjectsAdded);
            _fixtures.ObjectsRemoved += new EventHandler(_fixtures_ObjectsRemoved);
        }
Example #2
0
        private void newBodyToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var body = new BodyDefSerialized(null, new BodyDef(), new List<int>(), "Body");
            var node = new BodyNode(WorldObject, body);
            treeView1.Nodes[0].Nodes.Add(node);

            WorldObject.Bodies.Add(node);
        }
Example #3
0
        public void SerializeBody(BodyDefSerialized body)
        {
            writer.WriteStartElement("Body");
            writer.WriteAttributeString("Type", body.Body.BodyType.ToString());

            if (!string.IsNullOrEmpty(body.Name))
                writer.WriteElementString("Name", body.Name);

            #if !SKIP_DEFAULT_CHECKS
            if (body.Body.Active != defaultBodyDefData.Active)
            #endif
                writer.WriteElementString("Active", body.Body.Active.ToString());

            #if !SKIP_DEFAULT_CHECKS
            if (body.Body.AllowSleep != defaultBodyDefData.AllowSleep)
            #endif
                writer.WriteElementString("AllowSleep", body.Body.AllowSleep.ToString());

            #if !SKIP_DEFAULT_CHECKS
            if (body.Body.Angle != defaultBodyDefData.Angle)
            #endif
                writer.WriteElementString("Angle", body.Body.Angle.ToString());

            #if !SKIP_DEFAULT_CHECKS
            if (body.Body.AngularDamping != defaultBodyDefData.AngularDamping)
            #endif
                writer.WriteElementString("AngularDamping", body.Body.AngularDamping.ToString());

            #if !SKIP_DEFAULT_CHECKS
            if (body.Body.AngularVelocity != defaultBodyDefData.AngularVelocity)
            #endif
                writer.WriteElementString("AngularVelocity", body.Body.AngularVelocity.ToString());

            #if !SKIP_DEFAULT_CHECKS
            if (body.Body.Awake != defaultBodyDefData.Awake)
            #endif
                writer.WriteElementString("Awake", body.Body.Awake.ToString());

            #if !SKIP_DEFAULT_CHECKS
            if (body.Body.Bullet != defaultBodyDefData.Bullet)
            #endif
                writer.WriteElementString("Bullet", body.Body.Bullet.ToString());

            #if !SKIP_DEFAULT_CHECKS
            if (body.Body.FixedRotation != defaultBodyDefData.FixedRotation)
            #endif
                writer.WriteElementString("FixedRotation", body.Body.FixedRotation.ToString());

            #if !SKIP_DEFAULT_CHECKS
            if (body.Body.InertiaScale != defaultBodyDefData.InertiaScale)
            #endif
                writer.WriteElementString("InertiaScale", body.Body.InertiaScale.ToString());

            #if !SKIP_DEFAULT_CHECKS
            if (body.Body.LinearDamping != defaultBodyDefData.LinearDamping)
            #endif
                writer.WriteElementString("LinearDamping", body.Body.LinearDamping.ToString());

            #if !SKIP_DEFAULT_CHECKS
            if (body.Body.LinearVelocity != defaultBodyDefData.LinearVelocity)
            #endif
                WriteElement("LinearVelocity", body.Body.LinearVelocity);

            #if !SKIP_DEFAULT_CHECKS
            if (body.Body.Position != defaultBodyDefData.Position)
            #endif
                WriteElement("Position", body.Body.Position);

            if (body.Body.UserData != null)
            {
                writer.WriteStartElement("UserData");
                WriteDynamicType(body.Body.UserData.GetType(), body.Body.UserData);
                WriteEndElement();
            }

            writer.WriteStartElement("Fixtures");
            foreach (var fixture in body.FixtureIDs)
                writer.WriteElementString("ID", fixture.ToString());
            WriteEndElement();

            WriteEndElement();
        }