Object dragged inside a circle

Creating Games? Developing something for fun?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Surbhit29
Posts: 80
Joined: Thu Aug 16, 2012 1:25 pm

Object dragged inside a circle

Post by Surbhit29 » Fri Aug 17, 2012 6:38 am

I have an object Rectangle and it is draggable. The object is inside a circle. How can I restrict the path of the rectangle inside the circle, i.e the rectangle cannot be drag outside but within the circle.
Please tell me the code..

dave_probertGA6e24
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 328
Joined: Mon Dec 05, 2011 5:34 pm
Location: Thailand
Contact:

Re: Object dragged inside a circle

Post by dave_probertGA6e24 » Fri Aug 17, 2012 1:33 pm

You know the position of the centre of the enclosing circle. You know the current position of the centre of the dragged object. You know the radius of the enclosing circle. You know the size of the dragged object.

Use the basic distance calculation from the centre of the circle to the centre of the dragged object. Don't allow the object to move if the distance is more than the radius of the circle minus half the size of the object. The object should not then be able to appear outside the circle.

The actual code will be up to you, but the distance calculation is a simple Google search away and the rest is very simple.

Hope that helps.

Dave
Coding in the Sun - So much Fun.
Visit http://electronic-apps.info for released App information.

Surbhit29
Posts: 80
Joined: Thu Aug 16, 2012 1:25 pm

Re: Object dragged inside a circle

Post by Surbhit29 » Sat Aug 18, 2012 2:59 pm

Thnx Dave....
Will give it a try.... :)

Post Reply

Return to “Games”