This project has moved and is read-only. For the latest updates, please go here.

Gleed2d not linging up.

Topics: Developer Forum
Jun 22, 2011 at 10:27 PM

Been following some discussion here:

and feel a bit better about some issues I have had with getting my gleed2d level into farseer.  Things just are not lining up.  Image one is what it looks like in gleed2d and image 2 is what it looks like when loaded into farseer, also included is my code.


So why does my bounding parts look so different in farseer, thought it was a metersinpixels thing bout thought I accounted for it. 


In Farseer

in game:


This is the closest I have gotten to getting a level up with my game demo...before gleed2d I was using some   ScreenManager.LineBatch.DrawLineShape(_ground.FixtureList[i].Shape, Color.OliveDrab); that I would draw and the camera and movement

was working great, I think I might have to change how my camera works too :(  Also this is just the obsitcles from the level (rectangle primatives) the textures will be drawn differently more inline with what is seen on gleed2ds site.  For completeness at the end of the post I also put up the whole draw method too...


So what little piece of the puzzle am I missing that is causing those rectangles to be drawn so different from how I set it up in gleed2d to how i use it in game, I thought the using of MeterInPixels was the key, but I am still mistaken, any points in the right direction?


  private const float MeterInPixels = 64f;

 private void LoadLevel()

            level = Level.FromFile("level1.xml", ScreenManager.Content);
            Item hereoStart = level.getItemByName("heroStart");

            obsticles = new List<Item>();
            obsticles = level.getLayerByName("Obsticles").Items;
            Vector2[] groundPosition = new Vector2[level.getLayerByName("Obsticles").Items.Count];
            groundBody = new Body[level.getLayerByName("Obsticles").Items.Count];

            for (int obsticle = 0; obsticle < obsticles.Count; obsticle++)

                //need to get the size of the primatives
                groundPosition[obsticle] = obsticles[obsticle].Position / MeterInPixels + new Vector2(0, 1.25f);
                groundBody[obsticle] = BodyFactory.CreateRectangle(World, ((RectangleItem)obsticles[obsticle]).Width / MeterInPixels, ((RectangleItem)obsticles[obsticle]).Height / MeterInPixels, 1f, groundPosition[obsticle]);               
                groundBody[obsticle].Restitution = 0.3f;
                groundBody[obsticle].Friction = 0.5f;


public override void Draw(GameTime gameTime)

            Vector2 swordPos = _swordBody.Position;
            float swordRotation = _swordBody.Rotation;
            Vector2 swordPos2 = _swordBody.Position * MeterInPixels;

             //level drawing stuff...
            foreach (Layer layer in level.Layers)
                Vector2 oldcameraposition = Camera.Position;
                Camera.Position *= layer.ScrollSpeed;             

                ScreenManager.SpriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.AnisotropicClamp, DepthStencilState.None, RasterizerState.CullNone, null, Camera.View);

                Camera.Position = oldcameraposition;
            ScreenManager.SpriteBatch.Begin(0, null, null, null, null, null, Camera.View);


            ScreenManager.SpriteBatch.Draw(_swordSprite, ConvertUnits.ToDisplayUnits(swordPos), null, Color.White, swordRotation, new Vector2(_swordSprite.Bounds.Center.X, _swordSprite.Bounds.Center.Y), .5f, SpriteEffects.None, 0f);

            ScreenManager.SpriteBatch.Begin(0, null, null, null, null, null, Camera.View);
            ScreenManager.SpriteBatch.Draw(_polygonTexture, ConvertUnits.ToDisplayUnits(_compound.Position),
                                           null, Color.Tomato, _compound.Rotation, _origin, _scale, SpriteEffects.None,


Jun 23, 2011 at 3:47 AM

I had the exact same issue.  I noticed that it seems to not be an issue if you move away from 0,0 a bit.  I haven't found the time yet to figure out what's going on here, but it was really frustrating.

I was also looking into building an editor with the farseer physics built in and the capability to serialize the physics objects because I noticed that creating the objects from textures takes quite a while and it'd probably be better to pre-build those and serialize them out.

If you find a solution to this issue though, I may just go back to messing w/ gleed2d instead :)

Jun 23, 2011 at 3:15 PM


Im not sure if this will help you at all, but maybe you would want to take a look at my project I made with GLEED2D and Farseer. Its basicly Farseers "Hello World XNA" example with GLEED2D support. I have no idea what is wrong with your code and Im not even using Farseer nor GLEED2D in my current project. Just to notify you this is programmed VERY badly, for example there is no other classes than Game class, but when I did this couple weeks ago I had started XNA just week before. I posted a video about it on youtube also:, but I accidentaly deleted the .xml file GLEED2D generated so to level isnt same anymore but it works fine for me.

I uploaded this to Mediafire because last week one guy contacted me via youtube and asked me to upload it. Link.


Jun 24, 2011 at 7:24 AM

LOL that guy was me :) on youtube lollll i did get the code and used it but it still didn't line up.  I swear my camera is probably such  a hack and thats the issue :(

grinded to a halt (again on it) cause i just dunno what im doing wrong...and that doesnt even include the drawing of the textures later *Sigh*

Jun 24, 2011 at 9:49 AM

Oh :) Well.. This is really a long shot, but you could try to move all obsticles positions to positive coordinates if it would help. So 0,0 would be upper left corner of your world. But I gotta admit that this indeed kinda hard thing really understand, for example I was just last week was messing around with this and it took me like five hours to get this MeterInPixels thingy work. And after that I decided that I wont be using Farseer because it would have been easier to just use basic Rectangles instead of farseer stuff :P

Jul 4, 2011 at 11:48 PM

So I tried again last night to get this to work.  So frustrating... the boundries wont line up, I cannot tell if its a gleed2d,  farseer issue, a coding issue, a camera issue, or what.  Anyone else have any more luck??



Jul 18, 2011 at 6:27 AM

I just gotta beat this horse to death.  I am again spending an evening to try to resolve this issue, but still no luck.  I noticed this link here:


but this seems to not be the same issue, as just the debug drawing is even out of position for me, I haven't even textured it yet.  I know this is possible somebody posted this video:


(and no code *Sigh*) , and it looks slick, i would LOVE to get the level loading so I can start back in my design.... 


any one else still fighting with this? know of any other level editors easily integrateable into farseer?




Jul 18, 2011 at 11:00 AM

From your screenshots it looks to me like an origin problem.

Gleed regards the position of a rectangle to be its top left coordinate.  Farseer regards the position of an object to be the centre (or centre of gravity, not sure which).

Therefore, when you read in your gleed rectangles, into your game you need to take into account this difference. 

Farseer expects you to record the rectangle position as it's centre, so you need to calculate thatr centre and pass it to Farseer when you create it - I guess just add half the rectangles width and height to its Gleed position.

Jul 18, 2011 at 3:52 PM

Wow you are the man...that totally got it, i changed my code to:


 for (int obsticle = 0; obsticle < obsticles.Count; obsticle++)

                //need to get the size of the primatives               
                groundPosition[obsticle].X = obsticles[obsticle].Position.X/MeterInPixels + (((RectangleItem)obsticles[obsticle]).Width/MeterInPixels) / 2;
                groundPosition[obsticle].Y = obsticles[obsticle].Position.Y /MeterInPixels+ (((RectangleItem)obsticles[obsticle]).Height/MeterInPixels) / 2;

                groundBody[obsticle] = BodyFactory.CreateRectangle(World, ((RectangleItem)obsticles[obsticle]).Width / MeterInPixels, ((RectangleItem)obsticles[obsticle]).Height / MeterInPixels, 1f, groundPosition[obsticle]);               
                groundBody[obsticle].Restitution = 0.3f;
                groundBody[obsticle].Friction = 0.5f;


and that solved it, I will clean this up and start playing with Gleed2d now.  I will test with textures next.