2015-01-12 5 views
-1

나는 알파벳 문자 8x8 행렬을 가졌습니다. 나는이 문제를 극복하기 위해 레이블을 터치하고 이동할 때, 문자를 8x8 매트릭스.터치가 cocos2d에서 움직일 때 CCLabelTTF 스프라이트에서 유일한 문자를 얻는 방법

-(void)ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{ 
    UITouch *touch=[touches anyObject]; 
    CGPoint newlocation=[touch locationInView:[touch view]]; 

    newlocation=[[CCDirector sharedDirector] convertToGL:newlocation]; 
    for (int i=0; i<GRID_WIDTH; i++) { 
     for (int j=0; j<GRID_HEIGHT; j++) { 
     if (CGRectContainsPoint([grid[i][j].letter boundingBox],newlocation)) { 
      CCLOG(@"letters %@",[grid[i][j].letter string]); 
      [letterarray addObject:[grid[i][j].letter string]]; 
     } 
     } 
    } 
} 
+0

무슨 문제입니까? 귀하의 질문을 명확히하십시오. – YvesLeBorg

+0

I 해요 같이, 경계 상자를 통해 터치를 이동할 때 반복 편지를 받고 : B에게 B B W W W W W W W W W I I을 –

답변

0

아 ... 하나의 그리드 요소에 너무 많은 touchMoved 업데이트가 있습니다! 이것을 사용해보십시오

 if (CGRectContainsPoint([grid[i][j].letter boundingBox],newlocation)) { 
     CCLOG(@"letters %@",[grid[i][j].letter string]); 
     NSString *thisLetter = [grid[i][j].letter string]; 
     if (![letterArray containsObject:thisLetter]) { 
      [letterarray addObject:thisLetter]; 
     } else { 
      NSLog(@"*** Skipping letter, [%@] already in the array",thisLetter); 
     } 
    }