开发者

How to get tap location on world coordinate?

开发者 https://www.devze.com 2023-03-09 06:10 出处:网络
Can we be known of wher开发者_JAVA技巧e we have tapped(touched once) on a box2d world. As, location = [self convertCoordToLayer:location];

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);
0

精彩评论

暂无评论...
验证码 换一张
取 消