Computer Science Canada Create multiple buttons to click in one procedure |
Author: | Gaddy [ Sat Jan 12, 2013 1:06 pm ] |
Post subject: | Create multiple buttons to click in one procedure |
I am creating a game where i have to build a face. I have all the facial features in one procedure and i want to create buttons for each of them in one procedure. The problem is Turing only allows me to create one button and when i try to create another button the first one works but not the second. |
Author: | DemonWasp [ Sat Jan 12, 2013 1:39 pm ] |
Post subject: | RE:Create multiple buttons to click in one procedure |
It is definitely possible to create multiple buttons. You forgot to do the part where you tell us what you've tried and show us your code. We can't really help you without more details. |
Author: | Gaddy [ Sat Jan 12, 2013 1:52 pm ] |
Post subject: | Re: Create multiple buttons to click in one procedure |
%Display procedure display %Face drawoval (150, 200, 140, 200, black) %Eyes1 drawoval (340, 340, 30, 15, black) drawoval (430, 340, 30, 15, black) drawfilloval (340, 340, 13, 15, blue) drawfilloval (430, 340, 13, 15, blue) %Eyes2 drawoval (340, 380, 30, 15, black) drawoval (430, 380, 30, 15, black) drawfilloval (340, 380, 13, 15, brown) drawfilloval (430, 380, 13, 15, brown) %Eyes3 drawoval (340, 300, 30, 15, black) drawoval (430, 300, 30, 15, black) drawfilloval (430, 300, 13, 15, 84) drawfilloval (340, 300, 13, 15, 84) %Nose1 drawfilloval (550, 360, 30, 30, 40) %Nose2 drawfillbox (520, 260, 580, 320, black) %Mouth1 drawarc (390, 240, 85, 30, 180, 0, 1) %Mouth2 drawbox (310, 150, 480, 180, green) loop mousewhere (x, y, button) if button = 1 then %FOR Mouth 2 if (x >= 310 and x <= 480) and (y >= 150 and y <= 180) then %Mouth 2 drawbox (80, 70, 220, 100, green) end if %FOR NOSE 2 if (x >= 520 and x <= 580) and (y >= 260 and y <= 320) then %Nose2 drawfillbox (520, 260, 580, 320, black) end if end if end loop end display display So this is the part. I know you need mouse where in the loop so i have done that. I have to make buttons for each facial feature above but the first button works but the second doesnt |
Author: | Gaddy [ Sat Jan 12, 2013 1:54 pm ] |
Post subject: | Re: Create multiple buttons to click in one procedure |
Also if you can help me out for creating buttons within circles and on arcs would be helpful |
Author: | DemonWasp [ Sat Jan 12, 2013 4:04 pm ] |
Post subject: | RE:Create multiple buttons to click in one procedure |
Your button works fine. Your drawing coordinates are incorrect (and when you understand how they are incorrect, you'll understand why it doesn't look like the button works). To detect whether the mouse is within a circle, you can calculate the distance between the mouse (x,y) and the center of the circle's (x,y). If that's less than or equal to the radius of the circle, then the click was inside the circle. Ellipses (tall or short circles) are a little less straightforward. You should start with the general equation of an ellipse and work from there. Arcs are just portions of an ellipse. As a simplification, you could just detect clicks in a rectangular area that contains those shapes (the smallest rectangle around the arc, for example). |