bool MyScene::onTouchBegan(cocos2d::Touch* touch, cocos2d::Event* event) { auto location = touch->getLocationInView(); CCLOG("Touch began at (%f, %f)", location.x, location.y); return true; }
bool MyScene::onTouchBegan(cocos2d::Touch* touch, cocos2d::Event* event) { auto location = touch->getLocationInView(); auto camera = this->getDefaultCamera(); auto touchWorldPos = camera->convertToWorldSpaceAR({ location.x, location.y, 0 }); CCLOG("Touch began at world position (%f, %f)", touchWorldPos.x, touchWorldPos.y); return true; }This example is similar to the first one, but with an additional step of converting the touch location from view space to world space, using the default camera of the scene. This can be useful when you need to interact with 3D objects or sprites that are positioned in world space. Package/Library: cocos2d-x