2

cocos2d-js でスワイプ ジェスチャを使用する方法を調査していて、cocos2d で UISwipeGestureRecognizer が使用されていることがわかりました。しかし、cocos2d-js の場合は見つかりませんでした。

cocos2d のジェスチャー

また、github の cocos2d-x の場合:

CCGestureRecognizer

cocos2d-js については、私が見つけたものだけ

        cc.eventManager.addListener({
            event: cc.EventListener.TOUCH_ALL_AT_ONCE,
            onTouchesMoved:function (touches, event) {
                event.getCurrentTarget().processEvent(touches[0]);
            }
        }, this);

追加のイベント タイプ:

onTouchesBegan
onTouchesEnded
onTouchesCancelled

左、右、上、下のスワイプを検出するために cocos2d-js にあるのはこれだけですか?

4

3 に答える 3

1

これがcocos2d-jsスワイプでの私の解決策です

var cambaglayer = cc.Layer.extend({
                              ctor:function () {




                              this._super();
                              var size = cc.winSize;

                              touchCounter = 0;
                              if( true || 'touches' in cc.sys.capabilities ) {


                              cc.eventManager.addListener(cc.EventListener.create({
             event: cc.EventListener.TOUCH_ALL_AT_ONCE,
             onTouchesBegan: function(touches, event) {
             console.log("onTouchesBegan!");
             touchMenu();
             var touch = touches[0];
             var loc = touch.getLocation();
             this.touchStartPoint = {
             x: loc.x,
             y: loc.y
             };
             this.touchLastPoint = {
             x: loc.x,
             y: loc.y
             };
             },
             onTouchesMoved: function(touches, event) {
             var touch = touches[0];
             var loc = touch.getLocation(),
             start = this.touchStartPoint;
             console.log("onTouchesMoved!");
             console.log("onTouchesMoved!"+ touchThreshold);
             if( loc.x < start.x - touchThreshold ) {
             console.log("left!");
             if( loc.x > this.touchLastPoint.x ) {
             start = this.touchStartPoint = {
             x: loc.x,
             y: loc.y
             };
             this.isSwipeLeft = false;
             } else {
             this.isSwipeLeft = true;
             cc.log("swiping left side") 
             }
             }
             if( loc.x > start.x + touchThreshold ) {
             console.log("right!");

             if( loc.x < this.touchLastPoint.x ) {
             this.touchStartPoint = {
             x: loc.x,
             y: loc.y
             };
             this.isSwipeRight = false;
             } else {
             this.isSwipeRight = true;
             console.log("Swiping Right side");
             }
             }
             this.touchLastPoint = {
             x: loc.x,
             y: loc.y
             };
             },
             }
             ), this);
                              } else {
                              cc.log("TOUCH_ALL_AT_ONCE is not supported");
                              }
                              return true;
                              }
                              });
于 2015-08-27T07:03:39.880 に答える
0

完全な答えではありませんが、単にタッチの開始位置onTouchesBeganと終了位置を取得し、位置を差し引いて、最も変更された場所 (およびどのセクション)をonTouchesEnded見て、スワイプの方向を推測することができます。XY

上/下/左/右よりも強力なジェスチャ認識エンジンを探している場合は、supersuraccoon によるドル ジェスチャ認識エンジンを使用したこのサンプル プロジェクトを参照することしか考えられませんが、古いコード (v2 .2.2?) であり、cocos2d-html5 v3 ではイベント マネージャーが少し異なるため、現在のレベル以上の作業が必要になる可能性があります。

于 2014-05-23T16:21:11.953 に答える