cocos2dx 中如何把精灵移动到触摸点

2025-04-15 00:44:04
推荐回答(1个)
回答1:

在onToucheBegan里面设置精灵的position就好了
auto sp = this->getChildByTag(123); //假设精灵tag为123
CCPoint touchLocation = touch->getLocation(); // Get the touch position

touchLocation = this->convertToNodeSpace(touchLocation); //转换坐标系
sp->setPosition(touchLocation);