0

私の問題は、ccLayerがccTouchイベントを認識できるように、UIScrollViewを「ピアス」するソリューションが見つからなかったことです。

   self.isTouchEnabled = YES;
    [[NSBundle mainBundle] loadNibNamed:@"myLayer" owner:self options:nil];

..。

- (void) registerWithTouchDispatcher {
    [[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:self priority:INT_MIN swallowsTouches:NO];
    }

-(BOOL) ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event {
        CGPoint location = [self convertToWorldSpace:[self convertTouchToNodeSpace:touch]];

UIをバイパスしてccと通信するためのデリゲートまたは別のソリューションを作成する方法についてのアイデアはありますか?

4

1 に答える 1

2

私は今朝、Cocos2Dv1.0.0でこの問題を抱えていました。私の解決策は、レイヤーのinitメソッド内にCCTouchDispatcherメソッド呼び出しを含めることでした。そうすると、UIView内のそのレイヤーがタッチを認識します。

-(id) init
{
  if ((self = [super init]) != nil) {
    // do stuff
    [[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:self priority:0 swallowsTouches:YES];
  }
  return self;
}

-(BOOL) ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event
{
  CGPoint location = [self convertToNodeSpace:[[CCDirector sharedDirector] convertToGL:[touch locationInView:[touch view]]]];
  NSLog(@"TouchBegan at x:%0.2f, y:%0.2f", location.x, location.y);

  return YES;
}

別の解決策は、ccTouchesBeganメソッドを使用することです。

-(id) init
{
  if ((self = [super init]) != nil) {
    // do stuff
    self.isTouchEnabled = YES;
  }
  return self;
}


-(void) ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{   
  for (UITouch *thisTouch in touches) {
    CGPoint location = [self convertToNodeSpace:[[CCDirector sharedDirector] convertToGL:[thisTouch locationInView:[thisTouch view]]]];
    NSLog(@"TouchesBegan at x:%0.2f, y:%0.2f", location.x, location.y); 
  }
}

2つのタッチ方法には、タッチに応答する必要があることをアプリケーションに通知するための異なる方法があることに注意してください。タッチにどのように反応したいか、どのタッチを観察したいかを組み合わせることができません。

于 2011-08-17T05:55:25.003 に答える