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)];
}
但是,只觸及文本識別和精靈的觸摸不被識別? 我如何區分這兩個觸摸。任何人都可以提出比我的解決方案更好的方法。