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

Array of Edges

Mar 22, 2011 at 6:56 AM

I need some advice.  I'm currently developing a game that uses edges to construct my world boundaries.  I store all my edges in an array.  My intention is to be able to access this array to turn on/off the edges.  However, I'm noticing a slight hitch when my array size is over 100.  Is there a way I can disable all these edges all at once without having to go through my array and disabling each edge individually?  Thanks!

Mar 22, 2011 at 4:08 PM

Nevermind...I think I have an idea that might solve this issue.  I'll have to try it out after work.  Thanks!

Mar 22, 2011 at 4:44 PM

You could maybe use a loop shape and deactivate it as a whole. Of course this only applies if you have a closed loop of edges.

Mar 22, 2011 at 5:59 PM

Thanks Elsch!  I was thinking of the same thing or possibly using the texture to shape conversion to create a single body.  Either or, I'll try what you suggested. 

Since I am working on my first project using Farseer(coming from Box2D), I know Box2D had issues with closed shapes that were concave.  I wasn't sure if Farseer had the same issue.  But it's worth a try.

Thanks for the reply!  :)

Mar 25, 2011 at 4:04 PM

Elsch, thanks again for your advice!  I used the looped shaped method from the FixtureFactory and I store that to a fixture variable I can use to enable/disable the body's collisions.  However, there's still a slight hitch when I enable the collisions again.  But it did clean my code quite a bit!  :)

My next idea is to use collision categories similar to how one of the demo uses.  I'm just wondering if I can dynamically change the collision category whenever I need to?

But so far, the transition from Box2D to Farseer is pretty good!  There's a few little things that makes working with Farseer much easier.  Thanks again!

Mar 29, 2011 at 5:37 PM

Changing collision categories should work at run time. I'm not 100% sure though if it wakes sleeping bodies, so you might have to do that manually.

Mar 29, 2011 at 5:48 PM
Edited Mar 29, 2011 at 5:50 PM
Elsch wrote:

Changing collision categories should work at run time. I'm not 100% sure though if it wakes sleeping bodies, so you might have to do that manually.

Thanks again for the reply.  I haven't had the chance to try that method yet but hopefully I can get to it sometime this week.  At most, I only have 3 dynamic bodies in my world.  Two of which are attached to the world with a joint.  It's the third body I'm concerned about.  The rest of the world is static so I shouldn't have to worry about that going to sleep right?  To give you an idea of what I want to do is trying to give the world some depth by using sensors to turn on/off static collisions whenever the third body hits a sensor.  So say I have a ramp that looks like it's going over a wall, both the lower collision and the ramp have overlapping boundaries(or edges) and I'm using a sensor to manage which set of collisions turn on and off.  My guess is, if I can use the collision categories to do that instead of turning off the bodies' collisions, that might be faster and solve the hitching issue.

Again, thanks! :)