0
我正在编写一个应用程序在cocos2d。 我在我的场景中有一个精灵和一段文字。我为精灵和文本写了两个单独的类。我把他们俩都加到了另一个班上。
在精灵类我写如何区分图层上的两个不同的触摸?
- (void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
而且在文本类我已经写
-(void) registerWithTouchDispatcher
{
[[CCTouchDispatcher sharedDispatcher]addTargetedDelegate:self priority:0 swallowsTouches:YES];
}
-(BOOL) ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event
{
return YES;
}
-(void) ccTouchEnded:(UITouch *)touch withEvent:(UIEvent *)event
{
NSLog(@"Recognized tOuches in Instructions");//
CGSize windowSize = [[CCDirector sharedDirector] winSize];
CCNode *node = [self getChildByTag:kTagNode];
[node setPosition: ccp(text1.contentSize.width/2,text1.contentSize.height/2 - windowSize.height)];
}
-(void) ccTouchMoved:(UITouch *)touch withEvent:(UIEvent *)event
{
CGPoint touchLocation = [touch locationInView: [touch view]];
CGPoint prevLocation = [touch previousLocationInView: [touch view]];
touchLocation = [[CCDirector sharedDirector] convertToGL: touchLocation];
prevLocation = [[CCDirector sharedDirector] convertToGL: prevLocation];
CGPoint diff = ccpSub(touchLocation,prevLocation);
CCNode *node = [self getChildByTag:kTagNode];
CGPoint currentPos = [node position];
[node setPosition: ccpAdd(currentPos, diff)];
}
但是,只触及文本识别和精灵的触摸不被识别? 我如何区分这两个触摸。任何人都可以提出比我的解决方案更好的方法。