user3780799
user3780799

Reputation: 51

Cocos2d location in node

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

Answers (1)

Allen S
Allen S

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

Related Questions