How to get the location of the crane on a world coordinate?

Can we find out where we clicked (touched once) in the world of box2d. Since, location = [self convertCoordToLayer:location]; location.x,location.yreturns the coordinate of the screen. So, is there a way to get the world coordinate?

+3
source share
1 answer

It depends on how you relate your physical world and graphics. It’s usually enough to split the position of the touch relative to the PTM_RATIO layer:

    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);
+3
source

All Articles