我们能知道我们在 box2d 世界上点击过(触摸过一次)的位置吗?如,location = [self ConvertCoordToLayer:location];
location.x,location.y
返回屏幕坐标。那么有没有什么方法可以获取世界坐标呢?
最佳答案
这取决于您如何将物理世界和图形关联起来。通常,将相对于图层的触摸位置除以 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);
关于iphone - 如何获取世界坐标上的点击位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6188975/