简体   繁体   中英

How do I move a ball in a fixed circular/eclipse path for iPhone app

I need to move a ball in a circular path. Any guide or tutorials that I can refer to on how do I go about doing it? Thank you.

In terms of co-ordinates x and y it would just be

x = x_c + r cos(theta)
y = y_c + r sin(theta)

where (x_c,y_c) is the centre of the circle and r is its radius. If your xy system is one where the positive y direction is downwards then this would describe a clockwise path otherwise it's an anticlockwise path (as theta increases).

Edit

Just noticed you mentioned ellipses as well. If the ellipse is axis aligned then just use the major/minor radii instead eg.

x = x_c + a cos(theta)
y = y_c + b sin(theta)

Another way is to do this with Core Animation. Simply put the ball in a layer or view and make it move on a path. You can create the path with a series of bezier curves. You will have to understand a bunch of high level concepts but then the OS will take care of mostly everything involved.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM