多点触摸
@implementation TouchLayer
- (id) init
{
if ((self = [super init])) {
touchSpriteA_ =[CCSprite spriteWithFile:@"Icon.png"];
[self addChild:touchSpriteA_];
touchSpriteB_ =[CCSprite spriteWithFile:@"Icon.png"];
[self addChild:touchSpriteB_];
}
return self;
}
- (void) dealloc
{
[super dealloc];
}
- (void) onEnter
{
[super onEnter];
[[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:self priority:0 swallowsTouches:YES];
}
- (void) onExit
{
[[CCTouchDispatcher sharedDispatcher] removeDelegate:self];
[super onExit];
}
- (BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event
{
return YES;
}
- (void)ccTouchMoved:(UITouch *)touch withEvent:(UIEvent *)event;
{
CGPoint begen = [touch locationInView: [touch view]];
NSSet *allTouches = [event allTouches];//获得所有触摸点
int count = [[allTouches allObjects] count];//当前触摸点数量,单点触摸为1.
if (count == 1) {//单点触摸
UITouch *touch1 = [[allTouches allObjects] objectAtIndex:0];//获得第一个触摸点
switch ([touch1 tapCount]) {//判断是单击还是双击
case 1:
if (begen.y<550) {
}
NSLog(@"单击\n");
break;
case 2:
#pragma mark这里可以执行动画
NSLog(@"双击\n");
break;
}
}else if (count == 2) {//多点触摸
CGPoint touch0_point = [[[allTouches allObjects] objectAtIndex:0] locationInView: [touch view]];
CGPoint touch1_point = [[[allTouches allObjects] objectAtIndex:1] locationInView: [touch view]];
touchSpriteB_.position = touch0_point;
touchSpriteA_.position = touch1_point;
NSLog(@"两点触摸\n%f---%f",touch0_point.x,touch1_point.x);
}
}