Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

syednab

macrumors newbie
Original poster
Oct 18, 2008
2
0
Hi
I have a 2d-circle drawn as a view object using core graphics Frame work, on the touch of the circle i can move the circle . but My task is to slide the circle ,like when u drag the circle with certain speed then the circle should move(slide) and stop at any farther point.

I now i need to calculate the speed , distance moved and the destination point . but not clear how to do it. if any one have any similar example will be helpful. or any notes or guidance

I have to flick the circle in any direction and the circle should move and stop any where on the screen depending on the speed.
 
To do this properly the circle will need a few extra properties:-

Velocity
Speed
Direction
Drag factor (so friction can affect it)

If you are moving the circle based upon the speed of the finger flicking it you will need to track the finger over a set distance and apply the resulting velocity (speed and direction) to the circle when the finger is lifted. As the circle is moving you will then apply friction to it.

You could go as far as to have a mass property for the circle and base the drag factor on that but its much easier to hard code a drag factor in simple things such as this.

You will also need to take into account what happens when the circle hits the edges of the screen. You could either wrap it so it appears to come back onto the screen on the opposite side or you could check for collisions on the edges and when theres a collision, apply some damping to the speed and invert the direction of the circle so it appears to bounce off the edges.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.