I am trying to make my spriteNode rotate over my finger.
For now I can do this, but I want my node to have a "rotation speed". So I calculate the length of the angle, then set another time to rotate with it (if the arc is long, it will take time ...).
Here is my code:
override func touchesMoved(touches: NSSet, withEvent event: UIEvent) { _isTouched = true for touch in touches { let location:CGVector = touch.locationInNode(self) - miner.position miner.weaponRotation = location.angle() - CGFloat(M_PI_2) } } var wantedRotation: CGFloat { get { return _wantedRotation } set(rotation) { if rotation > CGFloat(M_PI) || rotation < -CGFloat(M_PI) { _wantedRotation = CGFloat(M_PI) + rotation % CGFloat(M_PI) } else { _wantedRotation = rotation } removeActionForKey("rotation") let arc: CGFloat = CGFloat(abs(_wantedRotation - zRotation)) let shortestArc: CGFloat = min(arc, CGFloat(M_PI * 2.0) - arc) runAction(SKAction.rotateToAngle(_wantedRotation, duration: NSTimeInterval(shortestArc / CGFloat(M_PI) * rotationSpeed), shortestUnitArc: true), withKey: "rotation") } }
The main problem is that adding multiple SKAction to a node blocks the movement.
I would like to know what could be the solution? If possible, using SKAction, since I would like to avoid updating each frame to calculate the motion (but if this is the only solution ...)
NOTE AFTER ANSWER
When I received the answers, I read the SpriteKit documentation again and found this clear note :
When you should not use actions
Although actions are effective, there are costs to create and execute them. If you make changes to the properties of node s in each frame of the animation, and these changes should be recounted in each frame, you better make changes to the node directly, rather than using actions to do this. For more information on where you can do this in your game, see the Advanced Scene Processing section.
source share