How to get tap location on world coordinate?
Can we be known of wher开发者_JAVA技巧e we have tapped(touched once) on a box2d world. As, location = [self convertCoordToLayer:location];
location.x,location.y
returns screen coordinate. So is there any method to get world coordinate?
That depends on how you correlate your physical world and the graphics. Usually it's enough to divide the touch position relative to the layer by PTM_RATIO:
CGPoint touchLocation = [touch locationInView:[touch view]];
touchLocation = [[CCDirector sharedDirector] convertToGL:touchLocation];
CGPoint nodePosition = [self convertToNodeSpace: touchLocation];
b2Vec2 pos(nodePosition.x/PTM_RATIO, nodePosition.y/PTM_RATIO);
精彩评论