diff --git a/core/Node/Node.cpp b/core/Node/Node.cpp index a3cccef1..56b8aa9b 100644 --- a/core/Node/Node.cpp +++ b/core/Node/Node.cpp @@ -90,11 +90,7 @@ void e2d::Node::_update() { if (_children.empty()) { - if (_autoUpdate && !Game::getInstance()->isPaused()) - { - this->onUpdate(); - } - this->_fixedUpdate(); + _updateSelf(); } else { @@ -117,21 +113,27 @@ void e2d::Node::_update() } } - if (_autoUpdate && !Game::getInstance()->isPaused()) - { - this->onUpdate(); - } - this->_fixedUpdate(); + _updateSelf(); // 访问其他节点 for (; i < _children.size(); ++i) _children[i]->_update(); } +} - // 更新转换矩阵 - updateTransform(); - // 保留差别属性 - _extrapolate = this->getProperty(); +void e2d::Node::_updateSelf() +{ + if (_needTransform) + { + updateTransform(); + CollisionManager::getInstance()->__updateCollider(&_collider); + } + + if (_autoUpdate && !Game::getInstance()->isPaused()) + { + this->onUpdate(); + } + this->_fixedUpdate(); } void e2d::Node::_render() @@ -141,6 +143,11 @@ void e2d::Node::_render() return; } + // 更新转换矩阵 + updateTransform(); + // 保留差别属性 + _extrapolate = this->getProperty(); + if (_children.empty()) { // 转换渲染器的二维矩阵 @@ -217,46 +224,6 @@ void e2d::Node::updateTransform() if (!_needTransform) return; - _updateSelfTransform(); - CollisionManager::getInstance()->__updateCollider(&_collider); - - if (_needTransform) - { - _updateSelfTransform(); - } - - // 为节点创建一个轮廓 - ID2D1RectangleGeometry * rectGeo = nullptr; - ID2D1TransformedGeometry * transformedGeo = nullptr; - - auto factory = Renderer::getFactory(); - HRESULT hr = factory->CreateRectangleGeometry( - D2D1::RectF(0, 0, _width, _height), - &rectGeo - ); - - if (SUCCEEDED(hr)) - { - factory->CreateTransformedGeometry( - rectGeo, - _finalMatri, - &transformedGeo - ); - } - - SafeRelease(rectGeo); - SafeRelease(_outline); - _outline = transformedGeo; - - // 通知子节点进行转换 - for (auto& child : _children) - { - child->_needTransform = true; - } -} - -void e2d::Node::_updateSelfTransform() -{ _needTransform = false; // 计算中心点坐标 @@ -288,6 +255,35 @@ void e2d::Node::_updateSelfTransform() // 更新碰撞体 _collider.recreate(); + + // 为节点创建一个轮廓 + ID2D1RectangleGeometry * rectGeo = nullptr; + ID2D1TransformedGeometry * transformedGeo = nullptr; + + auto factory = Renderer::getFactory(); + HRESULT hr = factory->CreateRectangleGeometry( + D2D1::RectF(0, 0, _width, _height), + &rectGeo + ); + + if (SUCCEEDED(hr)) + { + factory->CreateTransformedGeometry( + rectGeo, + _finalMatri, + &transformedGeo + ); + } + + SafeRelease(rectGeo); + SafeRelease(_outline); + _outline = transformedGeo; + + // 通知子节点进行转换 + for (auto& child : _children) + { + child->_needTransform = true; + } } void e2d::Node::_sortChildren() diff --git a/core/e2dnode.h b/core/e2dnode.h index a60bef65..a75fee81 100644 --- a/core/e2dnode.h +++ b/core/e2dnode.h @@ -394,6 +394,9 @@ protected: // 更新节点 void _update(); + // 更新自身 + void _updateSelf(); + // 渲染节点 void _render(); @@ -408,9 +411,6 @@ protected: Scene * scene ); - // 更新自身转换矩阵 - void _updateSelfTransform(); - // 子节点排序 void _sortChildren();