Objective c 为什么赢了';t我的Cocos2d测试应用程序fire“;“接触开始”;事件?

Objective c 为什么赢了';t我的Cocos2d测试应用程序fire“;“接触开始”;事件?,objective-c,cocos2d-iphone,Objective C,Cocos2d Iphone,在我的应用程序代理中,我确保我有以下行: [glView setMultipleTouchEnabled: YES]; 我有一个简单的图层,只是为了弄清楚多点触摸是如何工作的。.mm文件看起来像: #import "TestLayer.h" @implementation TestLayer -(id) init { if( (self=[super init])) { [[CCTouchDispatcher sharedDispatcher] addTarg

在我的应用程序代理中,我确保我有以下行:

    [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有效吗?即使我无法触发简单的多点触控事件,它也能工作吗?

UIgestureRecognitors绝对适用于Cocos2D,我个人使用过它们,您只需使用以下命令将它们添加到正确的视图中:

[[[CCDirector sharedDirector] openGLView] addGestureRecognizer:myGestureRecognizer];
关于你的触摸,我猜你在你工作的场景中启用了它们

scene.isTouchEnabled = YES;

在任何情况下,您都不应该使用
addTargetDelegate
方法,请查看add
self.isTouchEnabled=YES到您的init


对于手势识别器,请查看另一个答案

uigesturecognitioners
CCSprite上工作
?我不知道addTargetDelegate仅用于单触。谢谢如果我想要具有不同优先级的多个层,该怎么办?目标代理似乎在这方面很有用……特别是,现在我使用的是isTouchEnabled,我的第一层正在将它应该吞下的所有接触传递到下一层。