OGeek|极客世界-中国程序员成长平台

标题: ios - 如何在 Sprite 套件中实现齿轮接头? [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 14:55
标题: ios - 如何在 Sprite 套件中实现齿轮接头?

Box2d 中的齿轮接头很棒,但我不知道如何在 Sprite Kit 中实现它。有什么解决方案可以在 Sprite Kit 中实现齿轮接头吗?

谢谢。



Best Answer-推荐答案


以下是可用的 Sprite-Kit 关节:https://developer.apple.com/reference/spritekit/skphysicsjoint

enter image description here

据我了解,与 Box2D 的齿轮关节似乎没有直接关系,它似乎在另一个 body 旋转时使一个 body 旋转。

在这种情况下,您可能需要研究覆盖 didSimulatePhysics 或 didFinishUpdate 方法,以根据另一个对象的旋转手动设置一个对象的旋转:

https://developer.apple.com/reference/spritekit/skscene/1519965-didsimulatephysics

https://developer.apple.com/reference/spritekit/skscene/1520269-didfinishupdate

可能很简单:

wheel2.zRotation = wheel1.zRotation

但如果齿轮的齿数不同(因此传动比不同),您就必须进行一些计算。

关于ios - 如何在 Sprite 套件中实现齿轮接头?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42502669/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4