SKSpriteNode zrotate M_PI令人恼火

时间:2022-06-30 07:20:28

so all i want to do is rotate an SKSPriteNode by 90 degrees. just that. It should be simple yet my first approach, assuming it would be degrees, turns the object in completely the wrong diection. so i head to google > *. plenty of answers to do with this, okay so ill try using M_PI or some variation. nope. 'Double' is not convertible to 'CGFloat'. google again. "Try using skaction with blah blah" nope.

所以我要做的就是旋转一个SKSPriteNode 90度。只是这一点。它应该很简单,但我的第一种方法,假设它是度,把物体转到完全错误的角度。所以我想到谷歌> *。很多答案都是这样的,所以我会尝试使用M_PI或一些变体。不。“Double”不能转换为“CGFloat”。谷歌了。试着用一些废话。

how difficult can it be to rotate a sprite? or am i insane

旋转一个精灵有多难?还是我疯了

3 个解决方案

#1


2  

I'm assuming you're using Swift based on your "'Double' is not convertible..." comment.

我猜你使用Swift是因为你的“Double”是不可转换的。

The following rotates a sprite 90 degree counterclockwise:

下面逆时针旋转雪碧90度:

        sprite.runAction(SKAction.rotateByAngle(CGFloat(M_PI_2), duration: 1.0))

The following rotates a sprite 90 degree clockwise:

以下是顺时针旋转雪碧90度:

        sprite.runAction(SKAction.rotateByAngle(CGFloat(-M_PI_2), duration: 1.0))

#2


3  

This seems to work fine for me. Understanding conversions between radians and degrees is important. http://en.wikipedia.org/wiki/Radian#Conversion_between_radians_and_degrees

这对我来说似乎还行。理解弧度和角度之间的转换是很重要的。http://en.wikipedia.org/wiki/Radian Conversion_between_radians_and_degrees

sprite.zRotation = CGFloat(M_PI_2)

雪碧。zRotation = CGFloat(M_PI_2)

#3


0  

Another option would be to create an Extension for Int extension Int { var deg2Rad : CGFloat { return CGFloat(self) * CGFloat(M_PI) / 180.0 } }

另一个选项是为Int扩展创建一个扩展名Int (var deg2Rad: CGFloat(self) * CGFloat(M_PI) / 180.0}

then use it like this:

然后这样使用:

sprite.runAction(SKAction.rotateByAngle(180.deg2Rad, duration: 1.0))

时间函数sprite.runAction(SKAction.rotateByAngle(180.:1.0))

Makes it more human readable I think

我想,这让它更具可读性。

#1


2  

I'm assuming you're using Swift based on your "'Double' is not convertible..." comment.

我猜你使用Swift是因为你的“Double”是不可转换的。

The following rotates a sprite 90 degree counterclockwise:

下面逆时针旋转雪碧90度:

        sprite.runAction(SKAction.rotateByAngle(CGFloat(M_PI_2), duration: 1.0))

The following rotates a sprite 90 degree clockwise:

以下是顺时针旋转雪碧90度:

        sprite.runAction(SKAction.rotateByAngle(CGFloat(-M_PI_2), duration: 1.0))

#2


3  

This seems to work fine for me. Understanding conversions between radians and degrees is important. http://en.wikipedia.org/wiki/Radian#Conversion_between_radians_and_degrees

这对我来说似乎还行。理解弧度和角度之间的转换是很重要的。http://en.wikipedia.org/wiki/Radian Conversion_between_radians_and_degrees

sprite.zRotation = CGFloat(M_PI_2)

雪碧。zRotation = CGFloat(M_PI_2)

#3


0  

Another option would be to create an Extension for Int extension Int { var deg2Rad : CGFloat { return CGFloat(self) * CGFloat(M_PI) / 180.0 } }

另一个选项是为Int扩展创建一个扩展名Int (var deg2Rad: CGFloat(self) * CGFloat(M_PI) / 180.0}

then use it like this:

然后这样使用:

sprite.runAction(SKAction.rotateByAngle(180.deg2Rad, duration: 1.0))

时间函数sprite.runAction(SKAction.rotateByAngle(180.:1.0))

Makes it more human readable I think

我想,这让它更具可读性。