我希望能够为cocos2d启用多点触控。我怎样才能做到这一点?我想测试每个触摸事件,就像我的代码如下。请帮忙。如何启用多点触控cocos2d
-(void) ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *myTouch = [touches anyObject];
CGPoint location = [myTouch locationInView:[myTouch view]];
location = [[CCDirector sharedDirector] convertToGL:location];
b2Vec2 locationWorld = b2Vec2(location.x/PTM_RATIO, location.y/PTM_RATIO);
CGSize screenSize = [CCDirector sharedDirector].winSize;
if (locationWorld.x >= screenSize.width*2/5/PTM_RATIO && locationWorld.x <= screenSize.width*3.25/5/PTM_RATIO) {
cannonballTouch1 = 1;
float force = 6;
b2Vec2 direction = cannonballBody->GetWorldCenter() - cannonBody->GetWorldCenter();
b2Vec2 iforce = b2Vec2(1.0f/direction.x * force, 1.0f/direction.y * force);
NSLog(@"%.2f", direction.y);
NSLog(@"%.2f", iforce.y);
b2Vec2 force1 = b2Vec2(0, iforce.y);
cannonballBody->ApplyLinearImpulse(force1, cannonballBody->GetPosition());
}
if (locationWorld.x > screenSize.width*3.25/5/PTM_RATIO) {
cannonballTouch2 = 1;
float force = 6;
b2Vec2 direction = cannonballBody2->GetWorldCenter() - cannonBody2->GetWorldCenter();
b2Vec2 iforce = b2Vec2(1.0f/direction.x * force, 1.0f/direction.y * force);
NSLog(@"%.2f", direction.y);
NSLog(@"%.2f", iforce.y);
b2Vec2 force1 = b2Vec2(0, iforce.y);
cannonballBody2->ApplyLinearImpulse(force1, cannonballBody2->GetPosition());
}
}