mirror of https://github.com/axmolengine/axmol.git
issue #2771: fix physics test crashes
This commit is contained in:
parent
68b98fc84f
commit
8feb3a731b
|
@ -368,26 +368,25 @@ bool PhysicsDemo::onTouchBegan(Touch* touch, Event* event)
|
||||||
auto location = touch->getLocation();
|
auto location = touch->getLocation();
|
||||||
Array* arr = _scene->getPhysicsWorld()->getShapes(location);
|
Array* arr = _scene->getPhysicsWorld()->getShapes(location);
|
||||||
|
|
||||||
PhysicsShape* shape = nullptr;
|
PhysicsBody* body = nullptr;
|
||||||
for (Object* obj : *arr)
|
for (Object* obj : *arr)
|
||||||
{
|
{
|
||||||
shape = dynamic_cast<PhysicsShape*>(obj);
|
if ((dynamic_cast<PhysicsShape*>(obj)->getBody()->getTag() & DRAG_BODYS_TAG) != 0)
|
||||||
|
|
||||||
if ((shape->getTag() & DRAG_BODYS_TAG) != 0)
|
|
||||||
{
|
{
|
||||||
|
body = dynamic_cast<PhysicsShape*>(obj)->getBody();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (shape != nullptr)
|
if (body != nullptr)
|
||||||
{
|
{
|
||||||
Node* mouse = Node::create();
|
Node* mouse = Node::create();
|
||||||
mouse->setPhysicsBody(PhysicsBody::create(PHYSICS_INFINITY, PHYSICS_INFINITY));
|
mouse->setPhysicsBody(PhysicsBody::create(PHYSICS_INFINITY, PHYSICS_INFINITY));
|
||||||
mouse->getPhysicsBody()->setDynamic(false);
|
mouse->getPhysicsBody()->setDynamic(false);
|
||||||
mouse->setPosition(location);
|
mouse->setPosition(location);
|
||||||
this->addChild(mouse);
|
this->addChild(mouse);
|
||||||
PhysicsJointPin* joint = PhysicsJointPin::construct(mouse->getPhysicsBody(), shape->getBody(), location);
|
PhysicsJointPin* joint = PhysicsJointPin::construct(mouse->getPhysicsBody(), body, location);
|
||||||
joint->setMaxForce(5000.0f * shape->getBody()->getMass());
|
joint->setMaxForce(5000.0f * body->getMass());
|
||||||
_scene->getPhysicsWorld()->addJoint(joint);
|
_scene->getPhysicsWorld()->addJoint(joint);
|
||||||
_mouses.insert(std::make_pair(touch->getID(), mouse));
|
_mouses.insert(std::make_pair(touch->getID(), mouse));
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue