MCPcopy Create free account
hub / github.com/axmolengine/axmol / onTouchBegan

Method onTouchBegan

tests/cpp-tests/Source/PhysicsTest/PhysicsTest.cpp:262–294  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

260}
261
262bool 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
296void PhysicsDemo::onTouchMoved(Touch* touch, Event* /*event*/)
297{

Callers

nothing calls this directly

Calls 15

createFunction · 0.85
getShapesMethod · 0.80
getTagMethod · 0.80
addComponentMethod · 0.80
setMaxForceMethod · 0.80
addJointMethod · 0.80
constructFunction · 0.50
getLocationMethod · 0.45
getBodyMethod · 0.45
setDynamicMethod · 0.45
setPositionMethod · 0.45

Tested by

no test coverage detected