2011-06-27 78 views
0

我几乎我的比赛做,但我不能让我的多点触摸的工作:严重的多点触控问题

我在的appdelegate

[glView setMultipleTouchEnabled:YES]; 
(also tried [window setMultiTouchEnabled:YES];) 

得到了我Bomb.h

@interface Bomb : CCLayer (I also tried CCNode with <ccTargetTouchDelegate>) 

Bomb.m 

-(void)onEnter 
{ 
[[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:self priority:kCCMenuTouchPriority swallowsTouches:YES]; 
[super onEnter]; 
} 

-(void)onExit 
{ 
[[CCTouchDispatcher sharedDispatcher] removeDelegate:self]; 
[super onExit]; 
} 

(Also tried registerWithTouchDispatcher withouth onEnter and onExit and also tried with [super registerWithTouchDispatcher]) 

-(BOOL) ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event 
{ 
if(isPaused || !canBeDragged || LOST) 
return NO; 

//take the coordinates of the touch and transform them into the OpenGL system. 
CGPoint location = [touch locationInView: [touch view]]; 
location = [[CCDirector sharedDirector] convertToGL: location]; 

CGRect frame = CGRectMake(self.position.x, self.position.y, self.contentSize.width, self.contentSize.height); 

if(!CGRectContainsPoint(frame, location)) 
return NO; 

location.x *= factor; 
location.y *= factor; 

if(BombShape) 
{ 
offsetX = BombShape->body->p.x – location.x; 
offsetY = BombShape->body->p.y – location.y; 

BombShape->body->v = cpvzero; 
BombShape->collision_type++; //make it ‘Dragged’. For example RedNinja++ is DraggedRedNinja 
} 
return YES; 
} 
//**************************************************************************************** 
- (void) ccTouchMoved:(UITouch *)touch withEvent:(UIEvent *)event 
{ 
if(isPaused || !canBeDragged) 
return; 

CGPoint location = [touch locationInView: [touch view]]; 
location = [[CCDirector sharedDirector] convertToGL: location]; 

CGPoint prevLocation = [touch previousLocationInView: [touch view]]; 
prevLocation = [[CCDirector sharedDirector] convertToGL: prevLocation]; 

location.x *= factor; 
location.y *= factor; 

prevLocation.x *= factor; 
prevLocation.y *= factor; 

if(BombBody) 
{ 
//during the dragging, the bomb must not have velocity. Otherwise, it will “run” beneath your finger. 
//so we are constantly calculating the velocity and ,when you end the draging, assign that value to the velocity of the bomb. 
velocity = cpv((location.x – prevLocation.x) * 30 , (location.y – prevLocation.y)*30); 

CGPoint newPosition = cpv(location.x + offsetX, location.y + offsetY); 
//test per X 

canMoveOnX = CheckOnX(BombBody->p , newPosition,radius); 
canMoveOnY = CheckOnY(BombBody->p , newPosition,radius); 

if(canMoveOnX) 
BombBody->p.x = newPosition.x; 

if(canMoveOnY) 
BombBody->p.y = newPosition.y; 
} 
} 

//**************************************************************************************** 
- (void) ccTouchEnded:(UITouch *)touch withEvent:(UIEvent *)event 
{ 
if(!canBeDragged || isPaused) 
return; 

//set velocity back 
BombShape->body->v = velocity; 
BombShape->collision_type–; 

offsetX = 0; 
offsetY = 0; 
} 
//**************************************************************************************** 
-(void) ccTouchCancelled:(UITouch *)touch withEvent:(UIEvent *)event 
{ 

} 

不知何故,我似乎无法检测到我的第二个触摸:S。

我正在加载我的Bomb.h在一个没有触及CCLayer的GameScene中。

请帮忙。谢谢。

回答

1

我有同样的问题。

如果您有其他观点,例如广告观点,则应该做同样的事情。

ex。

[yourAnotherView setMultipleTouchEnabled:YES];

如果你没有,对不起,我不能回答更多...