0
votes

Im making a simple game with apple's SpriteKit and Swift and have encountered a problem. Im trying to get a paddle node (paddle) to rotate continuously around a fixed node (anchorNode) inside a circle; however, I cannot figure out how to make the paddle node (paddle) keep rotating around the fixed point node (anchorNode) because of the constrains in the SKAction.rotateByAngle statement making it end after a certain amount of time / rotation.

Any help is greatly appreciated!

Here is my code for reference:

    //Setting up anchor Node

    anchorNode.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame))
    anchorNode.size.height = (self.frame.size.height / 1000)
    anchorNode.size.width = anchorNode.size.height
    self.addChild(anchorNode)


    //Setting up achor Node's physucs

    anchorNode.physicsBody = SKPhysicsBody(circleOfRadius: (circle.frame.size.height / 1000))
    anchorNode.physicsBody?.dynamic = false
    anchorNode.physicsBody?.affectedByGravity = false
    anchorNode.physicsBody?.friction = 0


    //Making the anchor Node rotate

    let rotate = SKAction.rotateByAngle(CGFloat(3.14), duration: NSTimeInterval(1.5))
    anchorNode.runAction(rotate)



    //Setting up the paddle node

    paddle.position = CGPointMake((circle.frame.width / 2), 0)
    paddle.size.height = (self.frame.size.height / 50)
    paddle.size.width = (self.frame.size.width / 7)

    anchorNode.addChild(paddle)
2
anchorNode.runAction(SKAction.repeatActionForever(rotate))? - 0x141E

2 Answers

0
votes

Try adding this code.

override func update(currentTime: NSTimeInterval) {
//How to make it spin
let speed = CGFloat(5)
let degreeRotation = CDouble(speed) * M_PI / 180
paddle.zRotation -= CGFloat(degreeRotation)
}
0
votes

Using this fixed my problem:

anchorNode.runAction(SKAction.repeatActionForever(rotate))

Thanks, User:

0x141E