Exemple #1
0
void PhysicsWorld::removeBody(PhysicsBody* body)
{
    
    if (body->getWorld() != this)
    {
        CCLOG("Physics Warnning: this body doesn't belong to this world");
        return;
    }
    
    // destory the body's joints
    for (auto joint : body->_joints)
    {
        // set destroy param to false to keep the iterator available
        removeJoint(joint, false);
        
        PhysicsBody* other = (joint->getBodyA() == body ? joint->getBodyB() : body);
        other->removeJoint(joint);
        
        // test the distraction is delaied or not
        if (_delayRemoveJoints.size() > 0 && _delayRemoveJoints.back() == joint)
        {
            joint->_destoryMark = true;
        }
        else
        {
            delete joint;
        }
    }
    
    body->_joints.clear();
    
    removeBodyOrDelay(body);
    _bodies.eraseObject(body);
    body->_world = nullptr;
}
Exemple #2
0
void PhysicsWorld::removeAllBodies()
{
    for (auto& child : _bodies)
    {
        removeBodyOrDelay(child);
        child->_world = nullptr;
    }
    
    _bodies.clear();
}
void PhysicsWorld::removeAllBodies()
{
    for (Object* obj : *_bodies)
    {
        PhysicsBody* child = dynamic_cast<PhysicsBody*>(obj);
        removeBodyOrDelay(child);
        child->_world = nullptr;
    }

    _bodies->removeAllObjects();
    CC_SAFE_RELEASE(_bodies);
}
void PhysicsWorld::removeBody(PhysicsBody* body)
{
    
    if (body->getWorld() != this)
    {
        CCLOG("Physics Warnning: this body doesn't belong to this world");
        return;
    }
    
    // destory the body's joints
    for (auto joint : body->_joints)
    {
        removeJoint(joint, true);
    }
    
    removeBodyOrDelay(body);
    _bodies->removeObject(body);
    body->_world = nullptr;
}
void PhysicsWorld::removeBody(PhysicsBody* body)
{
    if (body->getWorld() != this)
    {
        CCLOG("Physics Warning: this body doesn't belong to this world");
        return;
    }
    
    // destroy the body's joints
    auto removeCopy = body->_joints;
    for (auto joint : removeCopy)
    {
        removeJoint(joint, true);
    }
    body->_joints.clear();
    
    removeBodyOrDelay(body);
    _bodies.eraseObject(body);
    body->_world = nullptr;
}