2012-03-01 45 views
1

在我的应用程序的委托,我确信我也行:为什么我的Cocos2d测试应用程序不会触发“touchesBegan”事件?

[glView setMultipleTouchEnabled: YES]; 

而且我有一个简单的一层意思只有弄清楚触摸如何多的工作。该.mm文件看起来像:

#import "TestLayer.h" 

@implementation TestLayer 
-(id) init 
{ 
    if((self=[super init])) { 
     [[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:self priority:0 swallowsTouches:YES]; 
    } 
    return self; 
} 

-(void) draw{ 
    [super draw]; 
    glColor4f(1.0, 0.0, 0.0, 0.35); 
    glLineWidth(6.0f); 
    ccDrawCircle(ccp(500,500), 250,CC_DEGREES_TO_RADIANS(360), 60,YES); 

} 

-(void) ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 
{ 
    NSLog(@"got some touches"); 
} 

-(void) ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event 
{ 
    NSLog(@"some touches moved."); 
} 

-(BOOL) ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event 
{ 
    NSLog(@"a touch began"); 
    return FALSE; 
} 
@end 

当我触摸屏幕时,我总是看到“触摸开始”,但无论怎样我触摸它(模拟器或实际设备),我从来没有看到“一些触摸移动“或”有些触动“。

我还需要做些什么才能使多点触摸工作?

具体来说,我只是想......我听说有某种手势识别为iPhone做基本的双指缩放功能......它为Coco2ds工作?即使我无法获得简单的多点触摸事件触发,它会工作吗?

回答

1

UIGestureRecognizers为Cocos2D中绝对的工作,我亲自使用过,你只需要通过将其添加到正确的观点:

[[[CCDirector sharedDirector] openGLView] addGestureRecognizer:myGestureRecognizer]; 

关于你的触动,我猜你使他们为你工作现场在?

scene.isTouchEnabled = YES; 

在任何情况下,你不应该使用addTargetDelegate方法,看看here

+0

是'UIGestureRecognizers'工作在'CCSprite'上? [CCGestureRecognizers](https://github.com/jerrodputman/CCKit/tree/master/CCKit) – 0xDE4E15B 2012-03-01 23:15:45

+0

我不知道addTargetDelegate只适用于单触式。谢谢! – Jenny 2012-03-02 13:56:14

+0

当我想拥有不同优先级的多个图层时如何?目标委托似乎是有用... – Jenny 2012-03-02 14:02:07

1

添加self.isTouchEnabled = YES;到您的init

和手势识别看着对方的回答

相关问题