Noob Question: How to make a button

Topics: User Forum
Feb 7, 2008 at 2:48 AM
I am working on created a Button class. Basically you specify a width, height, and position during the constructor and whenever you want to see the button' s status, just call isDepress() which will return true if the button is down and false if it isn't. I've got all the logic figured out and am using this technique to detect collisions with the button: http://www.codeplex.com/Thread/View.aspx?ProjectName=FarseerPhysics&ThreadId=15987 I do some storing of the old Y position of the button so it doesn't continually move down as the Collision handler is called. The problem I am having is i don't know how to detect when the object that was colliding with it is no longer colliding. I need this so I can return the button to its original up position. I'm doing this with a static Rectangle right now, maybe I need to be using a Spring or something... Anyone have any ideas or examples?
Feb 7, 2008 at 5:03 PM
Edited Feb 7, 2008 at 5:03 PM
By 'button', do you mean something that the user clicks on with a cursor, or something that a physics object is supposed land on and depress?

In the case of the former, there's a method in the PhysicsSimulator that will help you find an object at a specific location. This could be used with mouse coordinates to determine weather ot not the cursor is over the button.

PS: This is ment to be a physics object, affecting other physics objects, right? Some of the things you have said lead me to believe otherwise.
Feb 8, 2008 at 2:35 AM

Yota wrote:
By 'button', do you mean something that the user clicks on with a cursor, or something that a physics object is supposed land on and depress?

In the case of the former, there's a method in the PhysicsSimulator that will help you find an object at a specific location. This could be used with mouse coordinates to determine weather ot not the cursor is over the button.

PS: This is ment to be a physics object, affecting other physics objects, right? Some of the things you have said lead me to believe otherwise.


The latter... something that a physics object is suppose to land on and depress
Feb 8, 2008 at 2:35 AM
Edited Feb 8, 2008 at 2:36 AM
[ Removed Double Post ]
Feb 8, 2008 at 5:21 PM
Sounds like you have a similar question to one asked a few posts back.

See: Detect Stacked Objects