Computer Science Canada What is wrong with my drag program? |
Author: | Bo0sT [ Sat Jan 27, 2007 11:08 pm ] | ||
Post subject: | What is wrong with my drag program? | ||
I want to make games with turing but first I want to know how to do things like make dragable objects, iv made a sad attempt and I am hoping someone out there can help me out
|
Author: | Bored [ Sat Jan 27, 2007 11:28 pm ] | ||||||
Post subject: | Re: What is wrong with my drag program? | ||||||
Well your program just simply moves the object to where you click if you click within a certain range (i.e. (-1 - 11, -1 - 11)). What you need to do is have the program first figure out if you are clicking on the box. If so use a boolean value in order to say so. For example:
Which can then be shortened to
Clicking on box being you compassisons (i.e. and's, or's, ='s, etc.) Now once clicking on the box you should have it move to wherever the mouse is untill you release the mouse button. That would look something like this.
The second part simply resets drag to false when the button is released. I'll leave the rest of this up to you to figure out. |
Author: | CodeMonkey2000 [ Sun Jan 28, 2007 12:41 pm ] | ||||
Post subject: | Re: What is wrong with my drag program? | ||||
You are using constants to determin if the mouse is within the box. Use variables instead, since the box moves it's coordinates won't stay the same; they varry. Use names x1,y1,x2,y2 NOT a,e,c,d. Replace if x > -1 and x < 11 and y > -1 and y < 11 and b = 1 with variables. So it should look like this:
Now if you run this program and move the mouse quickly, the box wil not move. We can fix this by doing what bored did. Use booleans to determin if you still have the box. Your final code should look like this:
|