# Analog clock with pin joint

**URL:** <https://forums.kodeco.com/t/analog-clock-with-pin-joint/18089>\
**Category:** 2D iOS & tvOS Games by Tutorials\
**Created:** [August 3, 2016, 8:51am UTC](https://forums.kodeco.com/t/analog-clock-with-pin-joint/18089 "2016-08-03T08:51:22Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![kiaorasat](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/kiaorasat/32/60618_2.png) [@kiaorasat](https://forums.kodeco.com/u/kiaorasat)\
**Post date:** [August 3, 2016, 8:51am UTC](https://forums.kodeco.com/t/analog-clock-with-pin-joint/18089/1 "2016-08-03T08:51:22Z")

</div>

Hi all,

I’ve just completed Section II:(Physics and Nodes/Cat Nap) and now trying to deepen my understanding by playing with “Pin Joint”.  
I thought that an analog clock would be the easiest study for that purpose. 🙂  
However, it’s not working so far. So, I’m not sure if my direction and approach is right…

Do you use SpriteKit when you create a simple analog clock?

My goal is just to spin the clock hand(360 degrees) in accordance with the duration I configure such as 5 sec, 10 sec, 30 sec, and 60 sec.

 ![](https://raywenderlich-com-v3-forums.s3.amazonaws.com/original/3X/4/a/4a9beaf1761592bcfa42c64763414f2bc8875bd8.png)

Code snnipet

> import SpriteKit

> class ClockNode: SKSpriteNode, CustomNodeEvents {  
> private var clockBase = SKSpriteNode(imageNamed: “base”)  
> private var clockHand = SKSpriteNode(imageNamed: “hand”)  
> private var clockJoint: SKPhysicsJointPin!

> func didMoveToScene() {  
> guard let scene = scene else {  
> return  
> }  
> userInteractionEnabled = true
> 
> ```
> clockBase.anchorPoint = CGPoint(x: 0.5, y: 0.5) //center
> clockBase.position = position
> addChild(clockBase)
> 
> ```

> ```
> clockHand.anchorPoint = CGPoint(x: clockBase.position.x, y: clockBase.position.y)
> clockHand.position = position
> 
> ```

> ```
> let pinPoint = CGPoint(x: clockBase.position.x,y: clockBase.position.y)
> clockJoint = SKPhysicsJointPin.jointWithBodyA(clockBase.physicsBody!, bodyB: clockHand.parent!.physicsBody!, anchor: pinPoint)
> scene.physicsWorld.addJoint(clockJoint)
> 
> //clockHand.physicsBody!.allowsRotation = true
> //clockHand.physicsBody!.
> 
> addChild(clockHand)
> 
> clockHand.physicsBody!.applyImpulse(CGVector(dx: 50, dy: 25))
> 
> ```

> // let fortyFive = SKAction.rotateToAngle(CGFloat(3.14), duration: NSTimeInterval(1))  
> // clockHand.runAction(fortyFive)

> }  
> }

Many thanks in advance for your help.

---

<div class="post-metadata">

**Author:** ![kiaorasat](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/kiaorasat/32/60618_2.png) [@kiaorasat](https://forums.kodeco.com/u/kiaorasat)\
**Post date:** [August 3, 2016, 3:03pm UTC](https://forums.kodeco.com/t/analog-clock-with-pin-joint/18089/2 "2016-08-03T15:03:44Z")

</div>

Looks like one of the solutions is to add the followings. 😕

> ```
> clockHand.physicsBody!.mass = 0.0
> let action = SKAction.rotateByAngle(-CGFloat(M_PI) * 2, duration: 3) //
> 
> ```

```
clockHand.runAction(action, completion: { 
    print("done")
})

```
