示例#1
0
void Node::SetParent(Node* parent) {
    if(parent != nullptr) {
        if(parent->FindChildNode(mName, false) == nullptr) { // we are not already a child of the new parent
            if(mParent != nullptr) {                         // Remove it from its original parent.
                auto iter = mParent->mChildren.find(mName);
                parent->mChildren.insert(mName, mParent->mChildren.release(iter).release());
                mParent = parent;
            }
            else {
                parent->AddChildNode(this);
            }
            return;
        }
    }
    /*
    if(mParent != parent && mParent != nullptr) {
        // new parent
        mParent->RemoveChildNode(mName);
    } */

    mParent = parent;

    // the absolute position might have changed!
    _UpdateAllComponents(0);
}
示例#2
0
    ComponentType* AddComponent(ComponentType* component) {
        const QString& cname = component->GetName();
        if(!HasComponent(cname)) {
            std::shared_ptr<Component> ptr(component);
            ptr->SetNode(this);
            ptr->Initialize();
            std::pair<QString, std::shared_ptr<Component> > pair(cname, ptr);
            mComponents.insert(pair);
            
            if(!mIsEnabled)
                component->Disable();

            _UpdateAllComponents(0);
        } else {
            Logger::Get().Error("Cannot add component " + cname + ": a component with this name already exists.");
        }
        return FindComponent<ComponentType>(cname);
    }
示例#3
0
void Node::SetParent(Node* parent) {
    if(parent != nullptr) {
        if(parent->FindChildNode(mName, false) == nullptr) { // we are not already a child of the new parent
            parent->AddChildNode(this);
            return;
        }
    }
    /*
    if(mParent != parent && mParent != nullptr) {
        // new parent
        mParent->RemoveChildNode(mName);
    } */

    mParent = parent;

    // the absolute position might have changed!
    _UpdateAllComponents(0);
}
示例#4
0
void Node::OnUpdate(double time_diff) {
    if(mIsEnabled) {
        _UpdateAllChildren(time_diff);
        _UpdateAllComponents(time_diff);
    }
}