开发者

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 x-y 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜