Analog clock on SpriteKit

I just want the clock hand to spin 360 degrees but there’s something wrong…

スクリーンショット 2016-08-03 17.38.53.png

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)    

    addChild(clockHand)

    

    clockHand.physicsBody!.applyImpulse(CGVector(dx: 50, dy: 25))

  }

}

Advertisements

One thought on “Analog clock on SpriteKit

  1. 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”)
    })
    #########

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s