2011-10-14 5 views
1

편집 후cocos2d에서 멀티 터치를 어떻게 감지합니까?

내가 시도 좋아 무엇 rptwsthi 다른 프로젝트 단지 그것을 테스트하기로했다 ......

-(id) init 
{ 
if((self=[super init])) { 

    self.isTouchEnabled = YES; 
} 
return self; 
} 

- (void)ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event 
{ 
    NSArray *touchArray=[touches allObjects]; 

    if ([touchArray count] == 2) { 
     NSLog(@"touch 2"); 
    } 
    else if([touchArray count]==1) { 
     NSLog(@"touch 1"); 
    } 
} 

그러나

에만 나는를 누를 때 NSLog가 팝업을 "한 터치" 두 손가락으로 화면. LearnCocos2D가 말한 것을 어딘가에 넣어야합니까?

올드 포스트

은 내가 만들고있어 테스트 응용 프로그램을 가지고 있고 그 안에 내가 HUD 3 개 버튼이, 2 좌 · 우 및 다른 이동하면 촬영을위한위한 것입니다. 이것은 내가 현재 가지고있는 것입니다 .....

-(void) ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { 
UITouch *touch = [touches anyObject]; 
CGPoint loc = [touch locationInView:[touch view]]; 
loc = [[CCDirector sharedDirector] convertToGL:loc]; 

//Move Left 
CGRect left = CGRectMake(leftButton.position.x-50/2, leftButton.position.y-50/2, 50, 50); 
if (CGRectContainsPoint(left, loc)) { 
    [self schedule:@selector(moveLeft)]; 
} 

//Move Right 
CGRect right = CGRectMake(rightButton.position.x-50/2, rightButton.position.y-50/2, 50, 50); 
if (CGRectContainsPoint(right, loc)) { 
    [self schedule:@selector(moveRight)]; 
} 

//Shoot 
CGRect shoot = CGRectMake(shootButton.position.x-50/2, shootButton.position.y-50/2, 50, 50); 
    if (CGRectContainsPoint(shoot, loc)) { 
    bullet = [CCSprite spriteWithFile:@"bullet.png"]; 
    bullet.position = ccp(plane.position.x, plane.position.y+20); 
    [self addChild:bullet]; 
    } 
} 

-(void) ccTouchesEnded:(UITouch *)touch withEvent:(UIEvent *)event { 
    [self unschedule:@selector(moveLeft)]; 
    [self unschedule:@selector(moveRight)]; 
} 

그러나 한 번에 하나의 버튼 만 누를 수 있습니다. 오른쪽 또는 왼쪽 버튼을 누른 상태에서 촬영 버튼을 사용하여 촬영할 수 있기를 원합니다. 누구든지 내 코드를 수정하거나 멀티 터치의 기본 예제를 보여줄 수 있습니까?

또한 iOS 개발에 익숙하며 도움이 될 것입니다. 감사.

- (void)ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event 
{ 
    NSArray *touchArray=[touches allObjects]; 

    if ([touchArray count] == 2) 
     //DO ONE THING 
    else if([touchArray count]==1) 
     //DO ANOTHER THING 
} 

답변

3

당신은 그냥 좋아하는 대신 anyObjectallObject을 사용하고 확인?

[[CCDirector sharedDirector].openGLView setMultipleTouchEnabled:YES]; 
+0

내 게시물을 업데이트했습니다. 확인해 주시겠습니까? – user994620

+0

[이 링크 ..] (http://www.qcmat.com/dragging-multiple-sprites-in-cocos2d/)를 참조하면 더 많은 것을 얻을 수 있습니다. – rptwsthi

5

당신이적인 Cocos2D보기에서 여러 접촉을 활성화 :

+0

죄송합니다. 어떤 파일이 cocos2d 파일인지 확실하지 않습니다. – user994620

+0

당신은 scene의 init 메소드 나 어플리케이션 위임자의 applicationDidFinishLaunching 메소드와 같은 어디서나이 메소드를 호출 할 수 있습니다. – LearnCocos2D

관련 문제