首页 > 代码库 > cocos2d-x-3.x bringToFront & sendToBack实现
cocos2d-x-3.x bringToFront & sendToBack实现
void Node::bringToFront(void) { auto parent = this->getParent(); if (parent != nullptr && parent->getChildrenCount() >= 2) { auto& siblings = parent->getChildren(); auto last = *siblings.rbegin(); auto topOrderOfArrival = last->getOrderOfArrival(); auto topLocalZOrder = last->getLocalZOrder(); for (size_t idx = siblings.size() - 1; idx > 0; --idx) { auto sibling = siblings.at(idx); if (sibling != this) { sibling->setOrderOfArrival(siblings.at(idx - 1)->getOrderOfArrival()); sibling->_setLocalZOrder(siblings.at(idx - 1)->getLocalZOrder()); } else { break; } } this->setOrderOfArrival(topOrderOfArrival); this->_setLocalZOrder(topLocalZOrder); std::sort(std::begin(siblings), std::end(siblings), nodeComparisonLess); _eventDispatcher->setDirtyForNode(this); } } void Node::sendToBack(void) { auto parent = this->getParent(); if (parent != nullptr && parent->getChildrenCount() >= 2) { auto& siblings = parent->getChildren(); auto start = *siblings.begin(); auto bottomOrderOfArrival = start->getOrderOfArrival(); auto bottomLocalZOrder = start->getLocalZOrder(); for (size_t idx = 0; idx < siblings.size() - 1; ++idx) { auto c = siblings.at(idx); if (c != this) { c->setOrderOfArrival(siblings.at(idx + 1)->getOrderOfArrival()); c->_setLocalZOrder(siblings.at(idx + 1)->getLocalZOrder()); } else { break; } } this->setOrderOfArrival(bottomOrderOfArrival); this->_setLocalZOrder(bottomLocalZOrder); std::sort(std::begin(siblings), std::end(siblings), nodeComparisonLess); _eventDispatcher->setDirtyForNode(this); } }
cocos2d-x-3.x bringToFront & sendToBack实现
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。