0

SpriteBuilder を使用してゲームのレベルを設計しています。ゲームでは、スワイプすると動くブロック オブジェクトがあります。ただし、レベルにこれらのオブジェクトが複数ある場合、それぞれが最後に追加されたオブジェクトのみを参照します。それらはすべて固有のオブジェクトとして初期化されますが、スワイプしても動きません。正しく機能するのは、レベルに最後に追加されたものだけです。

スワイプジェスチャはこちらです。

- (void)didLoadFromCCB {
// Listen for swipe gestures to the right and left
UISwipeGestureRecognizer * swipeRight= [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipeRight)];
swipeRight.direction = UISwipeGestureRecognizerDirectionRight;
[[[CCDirector sharedDirector] view] addGestureRecognizer:swipeRight];

UISwipeGestureRecognizer * swipeLeft= [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipeLeft)];
swipeLeft.direction = UISwipeGestureRecognizerDirectionLeft;
[[[CCDirector sharedDirector] view] addGestureRecognizer:swipeLeft];
}

そして、これは、間違ったオブジェクトを自己として記録するスワイプ方法の 1 つです。また、正しいオブジェクトをログに記録するタッチ開始メソッドもあります。

- (void)swipeRight {

// Only move the object if it is being touched while swiping
CCLOG(@" Swipe right %@", self);
if (self.touched) {
    // Move the object off the screen to the right
    float width = [self parent].contentSizeInPoints.width;
    [self swipeOffScreen:ccp(self.position.x + width, self.position.y)];
}
}
4

1 に答える 1

0

swipeRight メソッドを使用する代わりに、コードを取得して touchEnded メソッドに移動し、touchMoved で self.touched を true に設定しました。問題は、UIKit スワイプ ラッパーと Cocos2D タッチ メソッドの違いだと思います。

于 2014-07-09T21:24:35.103 に答える