寻找旋转两个精灵的方法,这两个精灵是汽车的轮胎。
尝试使用RotateByAngle,但这使得轮胎离开它的位置比汽车大得多。我希望轮胎保持在完全相同的位置并永久旋转360度。像普通轮胎一样。
let wheel = SKAction.rotateByAngle(CGFloat(M_PI), duration:1)
playerWheelleft.runAction(SKAction.repeatActionForever(wheelSpeed))
如果对此问题有更好的解决方案,那么使用rotateByAngle请告诉我。
轮胎精灵不是中心的原因是因为我使用SKPhysicsJoint将两个轮胎连接到汽车的其他部分
var playerJoint = SKPhysicsJointPin.jointWithBodyA(player.physicsBody!, bodyB:playerWheelleft.physicsBody!, anchor:player.position)
self.physicsWorld.addJoint(playerJoint)
playerJoint = SKPhysicsJointPin.jointWithBodyA(player.physicsBody!, bodyB:playerWheelright.physicsBody!, anchor:player.position)
self.physicsWorld.addJoint(playerJoint)
我试图删除将轮胎与汽车其他部分连接起来的代码,然后轮换效果很好?
如何将轮胎作为中心旋转点?
let playerWheelsTexture = SKTexture(imageNamed: "playerWheel")
playerWheelleft = SKSpriteNode(texture: playerWheelsTexture)
playerWheelleft.position = CGPoint(x: CGRectGetMidX(self.frame) - 50, y: CGRectGetMidY(self.frame) - 320)
playerWheelleft.physicsBody = SKPhysicsBody(texture: playerWheelsTexture, size: playerWheelsTexture.size())
let wheelSpeed = SKAction.rotateByAngle(CGFloat(M_PI), duration:0.5)
playerWheelleft.runAction(SKAction.repeatActionForever(wheelSpeed))
playerWheelright.runAction(SKAction.repeatActionForever(wheelSpeed))