简体   繁体   English

如何在iPhone应用程序的固定圆形/椭圆路径中移动球

[英]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和y而言,

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. 其中(x_c,y_c)是圆的中心,r是圆的半径。 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). 如果您的xy系统是正y方向向下的系统,则这将描述一个顺时针路径,否则将是一个逆时针路径(随着theta的增加)。

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. 另一种方法是使用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. 您将必须理解一堆高级概念,但是操作系统将处理几乎所有涉及的事情。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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