Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Having troubles with my button
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Canibalistic Cow




PostPosted: Sat Jan 16, 2010 4:13 pm   Post subject: Having troubles with my button

What is it you are trying to achieve?
Make clickable button (make the button with the drawfilloval command)


What is the problem you are having?
half the button is clickable the other half isnt


Describe what you have tried to solve this problem
I went to all threads i have seen on this site, i have gotten the code for this button from http://compsci.ca/v3/viewtopic.php?t=3583&postdays=0&postorder=asc&start=15 (buttons for dummies)


Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)


Turing:


var mx, my, mb : int
var r := 60
loop
    mousewhere (mx, my, mb)
    if mb = 0 then
        drawfilloval (60, 60, r, r, blue)
    end if
    if mb = 1 and mx ** 2 + mb ** 2 <= r ** 2 then
        drawfilloval (60, 60, r, r, red)
    end if
end loop



Please specify what version of Turing you are using
4.1.1


So if anyone can help me with my button problem it sure would be helpful. I have looked through a lot of topics and i just cant seem to find out the answer.
Sponsor
Sponsor
Sponsor
sponsor
TerranceN




PostPosted: Sat Jan 16, 2010 6:44 pm   Post subject: Re: Having troubles with my button

You are calculating distance wrong, the formula is:

code:
Distance = sqrt((x1 - x2)**2 + (y1 - y2)**2)


Therefore in your code

x1 = mx
x2 = 60

y1 = my
y2 = 60

Or you could use Math.Distance(x1, y1, x2, y2)

Hope that helps
Canibalistic Cow




PostPosted: Sat Jan 16, 2010 10:59 pm   Post subject: Re: Having troubles with my button

Sorry but that isnt to helpful since i took the button to begin with i dont have any clue about the formula. :S thanks for trying to help though, anyone have another way they can maybe try to explain it or something. I am not that good at turing.
TheGuardian001




PostPosted: Sat Jan 16, 2010 11:05 pm   Post subject: Re: Having troubles with my button

Well, if the distance between the mouse (x1,y1) and the buttons center (x2,y2), which can be calculated with

TerranceN wrote:

code:
Distance = sqrt((x1 - x2)**2 + (y1 - y2)**2)



is less than the radius, then the mouse is over the button.
Canibalistic Cow




PostPosted: Sat Jan 16, 2010 11:20 pm   Post subject: Re: Having troubles with my button

Not quite sure what you guys ment but still they did help me find out my problem. i changed the code around a bit and this works:

Turing:


var mx, my, mb : int
var r := 60
loop
    mousewhere (mx, my, mb)
    if mb = 0 then
        drawfilloval (60, 60, r, r, blue)
    end if
    if mb = 1 and mx ** 1.70 + mb ** 2 <= r ** 2 then
        drawfilloval (60, 60, r, r, red)
    end if
end loop




is that right? like for what you guys were trying to tell me??
TerranceN




PostPosted: Sun Jan 17, 2010 1:24 am   Post subject: Re: Having troubles with my button

No, thats not what I was trying to tell you.

Since this button is a circle we can tell if the mouse is over it or not by comparing the radius of the button, to the distance between the middle of the button and the mouse position. The radius is just the distance from the middle to the edge of the circle. Therefore if the distance from the middle of the button to the mouse is less than or equal to the radius, the mouse is over the button.

If you are still unsure, look at richcash's Collision Detection Tutorial specifically the part about circle collision detection, just treat the mouse position as a circle with a radius of 0.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 6 Posts ]
Jump to:   


Style:  
Search: