How to rotate sprites around a joint

前端 未结 1 1531
小鲜肉
小鲜肉 2020-12-19 06:21

I need to make the arms and hands rotate around the center of the hook, as shown in the image below without them separating or changing their shape (no changes in the angles

相关标签:
1条回答
  • 2020-12-19 06:57

    You can make the arms and hands children of a common parent node. You could create a blank SKNode for just this purpose like so:

    let armsParent = SKNode()
    

    Then instead of adding the arms and hands as children to the scene directly, add them as children of armsParent like so:

    armsParent.addChild(leftArm)
    armsParent.addChild(rightArm) // same for hands...
    

    Then you can simply rotate armsParent with an SKAction to achieve what you want.

    OR, to make it even simpler, you could just add the arms and hands as children to hook directly like this:

    hook.addChild(leftArm) // same for other arm and hands...
    

    Since the arms and hands are children of hook or armParent their positions will now be determined relative to their parent. So you might have to change all your .position = initialization code to accommodate this.

    0 讨论(0)
提交回复
热议问题