我正在尝试根据 iPhone 的旋转(滚动)来旋转 Sprite 。 我将如何在 swift (4.2) 中做到这一点?我找到了使用 CMAttitude 的 Apple 文档,但我不明白如何将其实现为代码。 任何帮助表示赞赏, 谢谢!!!
最佳答案
"You access CMAttitude objects through the attitude property of each CMDeviceMotion objects passed to an application."
看看 CMDeviceMotion - 这才是真正必要的!
您需要CMMotionManager来接收您想要的内容。
也许是this link或this tutorial对你有帮助。
-> 开始使用 DeviceMotions 所需了解的一切
附加:
认为你在 SKit,它具有函数 rotate .
就这么简单:
根据手机的旋转,您可以
- 开始顺时针或逆时针旋转
- 停止旋转
- 甚至改变旋转
let angle : Float = (direction == yourDirection) ? Float(X) : -Float(X)
let rotate = SKAction.rotateByAngle(angle, duration: 1)
let repeatAction = SKAction.repeatActionForever(rotate)
sprite.runAction(repeatAction, withKey: "rotate")
关于ios - 如何根据手机旋转来旋转 Sprite ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52984695/