Best way to create a button?

Aug 13, 2008 at 5:14 PM
So far, I've created buttons by creating a Body without the PhysicsSimulator so it wouldn't move, and created the Geom with the PhysicsSimulator so that it would detect collision (with the mouse).

I've made a collision event between the mouse cursor's Geom and the button Geom, and then in the event method, I check for Left-Click.

This works okay, except the major flaw that the button's Geom is active for all other objects in play, and therefore screws up the playing field.

Anyone know a way using Farseer to create a button that won't interact with other objects?
Aug 13, 2008 at 8:14 PM
I think theres a sort of CollidesWith Command somewhere in farseer which would allow you to make it collide only with the mouse and the mouse colide only with the box...
Aug 13, 2008 at 8:28 PM
What Treacles says is true. There is a CollidesWith that takes a CollisionCategories category. There is also a CollisionCategories that contains the current categories.

If i remember correctly you can define multiple categories by using the | or & symbol.

Just wanted to compliment the answer from Treacles.
Aug 14, 2008 at 2:34 AM
If your buttons are static then why not just write up a quick button class that tests for mouseDown inside a bounding box. This would allow you to add cool stuff like buttons that glow when the mouse enters them and even drop down menus when you click. Unless your buttons are funky shapes I'd keep them separate from the simulation altogether. And even if they were funky shapes I'd still try and use the Geometry class separately from Farseer. By reading the code a little I can see an Intersect function. It does return a Feature but that shouldn't really matter as you'd only be interested in the bool value.
Aug 16, 2008 at 12:49 AM

Thanks for the input.

I went ahead and used the Rectangle class, and "IntersectsWith" for the bounding boxes. That seems to be the best way. =).

Aug 18, 2008 at 1:46 AM
No problem, I love to keep it simple.