Game Development Community

help setting area limits on buttons

by David Chutka · in Torque Game Builder · 06/26/2009 (9:48 am) · 10 replies

Okay, I'm going to apologize in advance for having larger ambitions than my extremely limited programming skills can manage to comprehend. That being said, hopefully someone here can help me out. The problem that I'm currently having is that I'm trying to find a way to make the buttons in my game work. As it sits right now the buttons aren't functional. The reason for that is because they overlap each other due to their shape / arrangement. If I were to make them functional right now you would often be pressing an incorrect button due to the overlapping that is occurring.

Essentially I have created a wheel. Each button is one section of the wheel (imagine a pizza cut into eight slices). Since each image is placed within a rectangle in TGB they all overlap the 'button' before it and after it which just leaves a small section in which you can actually click on the intended 'button'. I've done as much digging on the forums and tutorials as possible and the closest thing i can find is a function to set the area of an image, but that only seems to use two points (X1, Y1 / X2, Y2).

Is there a way to set the limits of something using four points? Since it is doable in collision detection I'm assuming there has to be a way to define four points instead of two. That way I could specify each corner of the 'button' and there would no longer be any overlapping. I have even thought about using a separate layer that just activates an animation or a different frame of an ImageMap in the layer below it.

Perhaps I'm on the wrong track and there is an easier way to do what i'm wanting to do. Regardless, I'm sure there is a way to do such a thing, I'm just limited by my programming knowledge. Any help would be appreciated.

#1
06/26/2009 (10:11 am)
you can change the collision option to poly then define however many points you want, that may work for you.
#2
06/26/2009 (10:25 am)
So collision responses work actions such as mouse clicks? I was under the impression that collision was just meant for in-game functions when objects collide. I will have to play around with things this weekend. I shall be pleased as punch if it is as simple as using collision detection.

Thanks for the quick response.
#3
06/26/2009 (10:35 am)
sorry misread your post, i thought you said you hooked this into collision already.
#4
06/26/2009 (10:45 am)
I get the impression that means that collision isn't the best method for solving this problem. If it helps any I have uploaded a picture.

http://www.davidchutka.com/images/buttons.png

Sorry again for the lack of knowledge. I'm learning things, just at a very slow pace. The help is greatly appreciated.
#5
06/26/2009 (2:22 pm)
are these gui buttons or scene objects?
#6
06/26/2009 (7:46 pm)
Well, I haven't touched GUI yet. Right now they are just scene objects that have three frames (0, 1, and 2). Each frame is a different color. The intent was to have it change to a different frame to change the button's color when it was clicked on. I would guess that there is a way to make this work, but perhaps this is the slow, hack-job way to do it.

In other words, would you suggest I spend a day working with GUI? The little that I read about it made it sound somewhat less customizable so i didn't really do a whole lot of investigating. If GUI is a better route I will just invest my next day off working my way through all the tutorials that involve it.

Thanks again for helping out.
#7
07/01/2009 (2:17 pm)
i'd stick with scene objects. though i still dont know a good way to do what you want.
#8
07/01/2009 (2:45 pm)
I'm extremely new myself so don't take my word for fact but I don't believe there's an easy way to do what you want. If I were in your shoes, I do it the slow and painful way of checking when a button is pressed to see if the click is really in the button area. Thankfully you have shapes with only 1 edge separating the good area from bad area so you don't have to do an overwhelming amount of tedious work.

I'd probably make a function that was called on a click that took the button image, the mouse event and two x,y points that define the line separating the good from the bad. It should then be some pretty simple match to determine if your click position is really in one of the buttons or not. Not a very elegant solution but it should work. Don't ask me what to do if you have overlapping buttons that are irregularly shaped.
#9
07/02/2009 (8:42 am)
Well, thank you both. I have been too busy to even check for responses over the past week, but I will see what i can do with Nate's suggestion. The other option is to take a step back and get less fancy. There is no reason why I would have to use a circle. I could easily change things up to be squares. One option requires spending a bit more time in photoshop, the other option requires me to spend time learning more programming. I get along much better with photoshop, so most likely that is the solution.

Regardless, many thanks for all the responses. Always appreciated.
#10
07/02/2009 (2:23 pm)
(edit: thought I had a better solution that didn't work out)