Sprite Kit - Determine vector of swipe gesture to flick sprite

后端 未结 3 1722
感动是毒
感动是毒 2021-02-02 04:14

I have a game where circular objects shoot up from the bottom of the screen and I would like to be able to swipe them to flick them in the direction of my swipe. My issue is, I

3条回答
  •  执笔经年
    2021-02-02 04:24

    In touchesBegan save the touch location as a CGPoint you can access throughout your app.

    In touchesEnded calculate the distance and direction of your initial touch (touchesBegan) and ending touch (touchesEnded). Then apply the appropriate Impulse.

    To refrain from double hitting, add a bool canHit that you set to NO when the impulse is applied and set back to YES when you are ready to hit again. Before applying the impulse, make sure canHit is set to YES.

提交回复
热议问题