How can I differentiate two different touches on a layer ?
Posted
by srikanth rongali
on Stack Overflow
See other posts from Stack Overflow
or by srikanth rongali
Published on 2010-04-14T13:40:25Z
Indexed on
2010/04/14
13:43 UTC
Read the original article
Hit count: 178
cocoa-touch
|cocos2d-iphone
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.
© Stack Overflow or respective owner