| 260 | } |
| 261 | |
| 262 | bool PhysicsDemo::onTouchBegan(Touch* touch, Event* event) |
| 263 | { |
| 264 | auto location = touch->getLocation(); |
| 265 | auto arr = _physicsWorld->getShapes(location); |
| 266 | |
| 267 | PhysicsBody* body = nullptr; |
| 268 | for (auto& obj : arr) |
| 269 | { |
| 270 | if ((obj->getBody()->getTag() & DRAG_BODYS_TAG) != 0) |
| 271 | { |
| 272 | body = obj->getBody(); |
| 273 | break; |
| 274 | } |
| 275 | } |
| 276 | |
| 277 | if (body != nullptr) |
| 278 | { |
| 279 | Node* mouse = Node::create(); |
| 280 | auto physicsBody = PhysicsBody::create(PHYSICS_INFINITY, PHYSICS_INFINITY); |
| 281 | physicsBody->setDynamic(false); |
| 282 | mouse->addComponent(physicsBody); |
| 283 | mouse->setPosition(location); |
| 284 | this->addChild(mouse); |
| 285 | PhysicsJointPin* joint = PhysicsJointPin::construct(physicsBody, body, location); |
| 286 | joint->setMaxForce(5000.0f * body->getMass()); |
| 287 | _physicsWorld->addJoint(joint); |
| 288 | _mouses.insert(std::make_pair(touch->getID(), mouse)); |
| 289 | |
| 290 | return true; |
| 291 | } |
| 292 | |
| 293 | return false; |
| 294 | } |
| 295 | |
| 296 | void PhysicsDemo::onTouchMoved(Touch* touch, Event* /*event*/) |
| 297 | { |
nothing calls this directly
no test coverage detected