This project has moved. For the latest updates, please go here.

Updating Geometry Position

Oct 19, 2010 at 2:10 PM
Edited Oct 20, 2010 at 2:25 PM



Im currently using Farseer Physics 2.1.3 for my game, now im using Layers for my textures. Now ive created geometry for my texture using Texture to Vertices however the texture position updates in my code so its got layer depth and other variables. However when the texture position updates its doesn't update my geometry. Is there a few of updating the geometry position, in the Update Method of my Texture to Vertices.


Heres my code

        private Vector2 _polygonOrigin;
        private Body _polygonBody;

        private Texture2D texture;
       // private Vector2 width;
        protected float width;
        protected float height;
        protected Vector2 origin;
       // private Vector2 position = new Vector2(400, 490);

        public GroundCollisionL1(PhysicsSimulator physics, Vector2 position, float width, float height, float mass,
            Texture2D texture)
            this.texture = texture;
            this.origin = new Vector2(texture.Width /2 , texture.Height /2);
            this.width = width;
            this.height = height;
           // Create(physics, position, width, height, mass, texture);

        public void Create()

            texture = Game1.LevelCollision;

            //Create an array to hold the data from the texture
            uint[] data = new uint[texture.Width * texture.Height];

            //Transfer the texture data to the array

            //Calculate the vertices from the array
            Vertices verts = Vertices.CreatePolygon(data, texture.Width, texture.Height);

            //Make sure that the origin of the texture is the centroid (real center of geometry)
            _polygonOrigin = verts.GetCentroid();

            //Use the body factory to create the physics body
            _polygonBody = BodyFactory.Instance.CreatePolygonBody(Farseer.Physics, verts, 5);
            _polygonBody.Position = new Vector2(texture.Width, texture.Height);

            _polygonBody.IsStatic = true;
            GeomFactory.Instance.CreatePolygonGeom(Farseer.Physics, _polygonBody, verts, 0);


        public virtual void Update()
                    // Update position taking into account that there needs to be a difference between the shapes position and the sprites position

             _polygonBody.Position = new Vector2(texture.Width, texture.Height);
            // Update rotation
                //sprite.RotationZ = body.Rotation;
        /// <summary>
        /// Draws this physics object
        /// </summary>       
        /// <param name="spriteBatch">SpriteBatch used to draw this object, should've already started.</param>
        public virtual void Draw(SpriteBatch SB)
           // spriteBatch.Begin();
            SB.Draw(texture, _polygonBody.Position, null, Color.White,
                                           _polygonBody.Rotation, _polygonOrigin, 1, SpriteEffects.None, 0);
            //spriteBatch.Draw(texture, new Vertices((int)body.Position.X, (int)body.Position.Y), (int)width, (int)height), null, Color.White, body.Rotation, origin, SpriteEffects.None, 0f);
            //spriteBatch.Draw(texture, new Rectangle((int)body.Position.X, (int)body.Position.Y, (int)width, (int)height), null, Color.White, body.Rotation, origin, SpriteEffects.None, 0f);


and in my level.cs

            irregularPlatform = new GroundCollisionL1(Farseer.Physics, new Vector2(Game1.LevelCollision.Width, Game1.LevelCollision.Height), 800, 600, 0.0f, Game1.LevelCollision);

Public Void Upodate(GameTime gt)




Could any one help me please. Thank You