Not very transparent

Jun 26, 2009 at 12:58 PM

Hi All,

I need a bit of a hand with collision lol

I have a body 'the ground' which is a wavy hill terrain. It is one texture2d. There is alpha transparency above the 'hills'.

My projectile bounces off the transparency probably the AABB.

Can I make farseer ignore alpha channels and collide with the wavy hill line instead.

Many Thanks


Jun 26, 2009 at 1:38 PM

Farseer has nothing to do with textures. It only does collisions with polygons that you have created. If you used the Texture-to-Vertices code where you give it a data array from the texture, then you can give it a higher alpha tolereance. You also might want to put the PhysicsSimulatorView into your project to see where you have polygons and the like. It is good for debugging.

Jun 26, 2009 at 5:13 PM

The question to ask here is how did you create the geometry for the ground?  It is the geometry, and nothing else, which determines collisions.

Jun 29, 2009 at 8:31 AM

Hi Guys,

Thanks for the reply my objects are created as follows:

arrowBody1 = BodyFactory.Instance.CreateRectangleBody(physicsSimulator, 60, 10, 1f);
arrowBody1.Position = new Vector2(20, 400);
arrowBody1.IgnoreGravity = true;
arrowGeom1 = GeomFactory.Instance.CreateRectangleGeom(physicsSimulator, arrowBody1, 60, 10);
arrowGeom1.OnCollision = onHit;

groundBody = BodyFactory.Instance.CreateRectangleBody(physicsSimulator, 800, 54, 1f);
groundBody.Position = new Vector2(0, 546);
groundBody.IgnoreGravity = true;
groundBody.IsStatic = true;
groundGeom = GeomFactory.Instance.CreateRectangleGeom(physicsSimulator, groundBody, 800, 54);
I am guessing this just creates an AABB for the ground should I do it?
Many Thanks


Jun 29, 2009 at 2:23 PM

Basically, yes, this code is only making a rectangle for the Geometry, which acts pretty much the same as an AABB (assuming you don't rotate).  Instead, do 1 of 2 things.  Manually create a set of vertices that matches the outline of your ground, or use the Texture to Vertices code in the manual (page 28):

//Load texture that will represent the physics body
Texture2D polygonTexture = ScreenManager.ContentManager.Load<Texture2D>("Content/Texture");
//Create an array to hold the data from the texture
uint[] data = new uint[polygonTexture.Width * polygonTexture.Height];
//Transfer the texture data to the array
//Calculate the vertices from the array
Vertices verts = Vertices.CreatePolygon(data, polygonTexture.Width, polygonTexture.Height);
//Make sure that the origin of the texture is the centroid (real center of geometry)
Vector2 polygonOrigin = verts.GetCentroid();
//Use the body factory to create the physics body
Body polygonBody = BodyFactory.Instance.CreatePolygonBody(PhysicsSimulator, verts, 5);
polygonBody.Position = new Vector2(500, 400);
GeomFactory.Instance.CreatePolygonGeom(PhysicsSimulator, polygonBody, verts, 0);

I currently use this code, and it does a pretty decent job of creating a set of vertices that follows the alpha channel of the image used.

Check out page 30 in the manual as well.  You'll probably want to split up your background into multiple objects if things run slow.

Jul 1, 2009 at 8:04 AM

Hi Guys,

Just a not to thank you for your help it is much appreciated :)



Jul 1, 2009 at 9:20 AM


That code sort of worked only it still didn't take into account the alpha ideas

Thanks for all your help