Objective c 节点中的Cocos2d位置

Objective c 节点中的Cocos2d位置,objective-c,cocos2d-iphone,touch,Objective C,Cocos2d Iphone,Touch,我在cocos2d中使用触摸,完全误解了获取触摸位置的方法。 例如,此方法返回一个结果: CGPoint curLocation = [touch locationInView:[touch view]]; CGPoint a = [[CCDirector sharedDirector] convertToGL:curLocation]; CGPoint touchLoc = [touch locationInNode:self]; CGPoint point

我在cocos2d中使用触摸,完全误解了获取触摸位置的方法。 例如,此方法返回一个结果:

    CGPoint curLocation = [touch locationInView:[touch view]];
    CGPoint a = [[CCDirector sharedDirector] convertToGL:curLocation];

    CGPoint touchLoc = [touch locationInNode:self];
    CGPoint point = [self convertToNodeSpace:touchLoc];

那么什么时候需要使用哪些方法呢?因为在文档0中,您需要的是关于这一点的信息。

在cocos2d v3中,您只需要:

CGPoint touchLoc = [touch locationInNode:self];
如果查看locationInNode代码,它已经调用了convertToGL和convertToNodeSpace。您不应该在之后调用convertToNodeSpace,因为这样会得到不正确的结果。只需使用locationInNode。前两行和第四行已经在locationInNode中完成