Detect an open pinch - like UIPinchGestureRecognizer, programmatically in a Box2D/cocos2d world?

佐手、 提交于 2019-12-12 01:58:22

问题


I'm using the UIPinchRecognizer and an open pinch to detect when someone 'pulls apart' a sprite in a Box2D world.

If I use UIPinchGestureRecognizer to detect pull aparts, it breaks my mouse joints when two objects are dragged together - which is less than ideal. I've tried to split my problem into two questions - how to detect an open pinch without UIPinchGestureRecognizer and is it is possible to suppress the close pinch.

How can I write my own class to detect an open pinch? That is, two fingers on an object moving apart? This is pretty daunting for me and I'm not sure where to start. It looks like you can subclass UIGestureRecognizer to help in these situations.

UPDATE

Here's what I want to achieve.

  1. The user puts two fingers on an box2d /sprite object
  2. The user pulls those fingers apart, like an open pinch
  3. The object splits in half (I've implemented this bit)

That's the only time I need the UIPinchGestureRecognizer. The user will be moving multiple objects around with multiple fingers - I don't want the pinch gesture to be triggered when different objects are being moved toward one another.

I made a really amazing diagram showing what I want - the blue bits represent touches/direction. Please excuse my mad photoshop skills:

来源:https://stackoverflow.com/questions/10185556/detect-an-open-pinch-like-uipinchgesturerecognizer-programmatically-in-a-box2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!