J'écris une application dans cocos2d. J'ai un sprite et un texte dans ma scène. J'ai écrit deux classes séparées pour le sprite et le texte. Et j'ai ajouté les deux à une autre classe.
En classe sprite j'ai écritComment puis-je différencier deux touches différentes sur une couche?
- (void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
Et dans la classe de texte j'ai écrit
-(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)];
}
Mais, ne touche dans le texte sont reconnus et le toucher de sprite est pas reconnu? Comment puis-je différencier les deux touches. Quelqu'un peut-il suggérer une meilleure méthode pour cela que ma solution.