I am writing an app in cocos2d.
I hava a sprite and a text in my scene. I have written two separate classes for sprite and text. And I added both of them to another class.
In sprite class I have written
- (void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
And in text class I have written
-(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)];
}
But, only touches in the text are recognized and touch of sprite is not recognized ? How can I differentiate the two touches. Can anyone suggest better method for it than my solution.