[英]Swift & Sprite-Kit: How to rotate sprites to the direction set by collision?
I'm new to game physics. 我是游戏物理学的新手。 I would like to create a sprite in Sprite-kit where the sprite would rotate as it collides with screen boundaries or other objects in the game.
我想在Sprite-kit中创建一个Sprite,当Sprite与屏幕边界或游戏中的其他对象碰撞时Sprite会旋转。 Basically like so.
基本上是这样的。
I just have no idea how this is done in Sprite-Kit or with any other framework for that matter... Do I have to calculate rotations in code or does the framework offer assistance? 我只是不知道如何在Sprite-Kit或任何其他框架中完成此操作……我是否必须计算代码中的旋转量,或者该框架是否提供帮助? If this is going to be done in my code, could someone help me get started?
如果这将在我的代码中完成,有人可以帮助我入门吗? Thanks a bunch already!
多谢了!
Use the following SKAction: 使用以下SKAction:
let action = SKAction.rotateByAngle(CGFloat(M_PI), duration:5)
sprite.runAction(action)
This will rotate the sprite 180º 这将使精灵旋转180º
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.