Reputation: 51
i'm working with touch in cocos2d and completely misunderstood with methods of getting position of touch. For example, this methods returns one result:
CGPoint curLocation = [touch locationInView:[touch view]];
CGPoint a = [[CCDirector sharedDirector] convertToGL:curLocation];
CGPoint touchLoc = [touch locationInNode:self];
CGPoint point = [self convertToNodeSpace:touchLoc];
So which methods when need to use ? because in documentation 0 info about that.
Upvotes: 0
Views: 130
Reputation: 1042
In cocos2d v3 all you need is the:
CGPoint touchLoc = [touch locationInNode:self];
If you look in the locationInNode code, it already calls convertToGL and convertToNodeSpace. You shouldn't be calling convertToNodeSpace afterwards because that will give you incorrect results. Just use locationInNode. The first two lines and the fourth line you have are already done inside locationInNode.
Upvotes: 1