2018-04-21 21:24:46 +08:00
|
|
|
|
#include "..\e2dnode.h"
|
|
|
|
|
|
#include "..\e2dmanager.h"
|
|
|
|
|
|
#include "..\e2daction.h"
|
2017-10-14 18:43:32 +08:00
|
|
|
|
#include <algorithm>
|
2017-10-12 23:34:13 +08:00
|
|
|
|
|
2017-11-09 18:22:41 +08:00
|
|
|
|
// Ĭ<><C4AC><EFBFBD><EFBFBD><EFBFBD>ĵ<EFBFBD>λ<EFBFBD><CEBB>
|
|
|
|
|
|
static float s_fDefaultPiovtX = 0;
|
|
|
|
|
|
static float s_fDefaultPiovtY = 0;
|
2018-04-02 23:01:38 +08:00
|
|
|
|
static bool s_fDefaultColliderEnabled = true;
|
2017-11-09 18:22:41 +08:00
|
|
|
|
|
2018-02-07 16:37:12 +08:00
|
|
|
|
e2d::Node::Node()
|
2018-05-08 17:40:36 +08:00
|
|
|
|
: _nOrder(0)
|
2018-05-09 00:34:15 +08:00
|
|
|
|
, _posX(0)
|
|
|
|
|
|
, _posY(0)
|
|
|
|
|
|
, _width(0)
|
|
|
|
|
|
, _height(0)
|
|
|
|
|
|
, _scaleX(1.0f)
|
|
|
|
|
|
, _scaleY(1.0f)
|
|
|
|
|
|
, _rotation(0)
|
|
|
|
|
|
, _skewAngleX(0)
|
|
|
|
|
|
, _skewAngleY(0)
|
|
|
|
|
|
, _displayOpacity(1.0f)
|
|
|
|
|
|
, _realOpacity(1.0f)
|
|
|
|
|
|
, _pivotX(s_fDefaultPiovtX)
|
|
|
|
|
|
, _pivotY(s_fDefaultPiovtY)
|
|
|
|
|
|
, _initialMatri(D2D1::Matrix3x2F::Identity())
|
|
|
|
|
|
, _finalMatri(D2D1::Matrix3x2F::Identity())
|
|
|
|
|
|
, _visiable(true)
|
|
|
|
|
|
, _collider(nullptr)
|
|
|
|
|
|
, _parent(nullptr)
|
|
|
|
|
|
, _parentScene(nullptr)
|
|
|
|
|
|
, _hashName(0)
|
|
|
|
|
|
, _needSort(false)
|
|
|
|
|
|
, _needTransform(false)
|
|
|
|
|
|
, _autoUpdate(true)
|
|
|
|
|
|
, _positionFixed(false)
|
2017-10-12 23:34:13 +08:00
|
|
|
|
{
|
2018-04-02 23:01:38 +08:00
|
|
|
|
if (s_fDefaultColliderEnabled)
|
2018-03-07 20:14:58 +08:00
|
|
|
|
{
|
2018-05-19 01:10:37 +08:00
|
|
|
|
this->setCollider(GC::create<ColliderRect>(this));
|
2018-03-07 20:14:58 +08:00
|
|
|
|
}
|
2017-10-12 23:34:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-07 16:37:12 +08:00
|
|
|
|
e2d::Node::~Node()
|
2017-10-12 23:34:13 +08:00
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-07 16:37:12 +08:00
|
|
|
|
void e2d::Node::_update()
|
2017-10-14 18:43:32 +08:00
|
|
|
|
{
|
2018-05-09 00:34:15 +08:00
|
|
|
|
if (_needTransform)
|
2017-10-15 23:58:39 +08:00
|
|
|
|
{
|
2018-04-24 10:35:58 +08:00
|
|
|
|
_updateTransform();
|
2017-10-15 23:58:39 +08:00
|
|
|
|
}
|
2017-10-14 18:43:32 +08:00
|
|
|
|
|
2018-05-09 00:34:15 +08:00
|
|
|
|
if (!_children.empty())
|
2017-10-14 18:43:32 +08:00
|
|
|
|
{
|
2018-05-09 00:34:15 +08:00
|
|
|
|
if (_needSort)
|
2018-02-03 22:04:43 +08:00
|
|
|
|
{
|
2018-02-11 20:48:56 +08:00
|
|
|
|
// <20>ӽڵ<D3BD><DAB5><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
auto sortFunc = [](Node * n1, Node * n2) {
|
|
|
|
|
|
return n1->getOrder() < n2->getOrder();
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2018-02-03 22:04:43 +08:00
|
|
|
|
std::sort(
|
2018-05-09 00:34:15 +08:00
|
|
|
|
std::begin(_children),
|
|
|
|
|
|
std::end(_children),
|
2018-02-11 20:48:56 +08:00
|
|
|
|
sortFunc
|
2018-02-03 22:04:43 +08:00
|
|
|
|
);
|
2017-10-14 18:43:32 +08:00
|
|
|
|
|
2018-05-09 00:34:15 +08:00
|
|
|
|
_needSort = false;
|
2018-02-03 22:04:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>ӽڵ<D3BD>
|
2018-05-09 00:34:15 +08:00
|
|
|
|
size_t size = _children.size();
|
2017-12-15 23:15:06 +08:00
|
|
|
|
size_t i;
|
2018-05-14 22:51:40 +08:00
|
|
|
|
for (i = 0; i < size; ++i)
|
2017-10-14 18:43:32 +08:00
|
|
|
|
{
|
2018-05-09 00:34:15 +08:00
|
|
|
|
auto child = _children[i];
|
2017-10-14 18:43:32 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD> Order С<><D0A1><EFBFBD><EFBFBD><EFBFBD>Ľڵ<C4BD>
|
|
|
|
|
|
if (child->getOrder() < 0)
|
|
|
|
|
|
{
|
2018-02-06 21:11:54 +08:00
|
|
|
|
child->_update();
|
2017-10-14 18:43:32 +08:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-05-19 00:00:12 +08:00
|
|
|
|
if (_autoUpdate && !Game::isPaused())
|
2018-02-04 21:24:27 +08:00
|
|
|
|
{
|
2018-05-19 00:00:12 +08:00
|
|
|
|
this->onUpdate();
|
2018-02-03 22:04:43 +08:00
|
|
|
|
}
|
2018-05-19 00:00:12 +08:00
|
|
|
|
this->_fixedUpdate();
|
2017-10-14 18:43:32 +08:00
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD>ʣ<EFBFBD><CAA3><EFBFBD>ڵ<EFBFBD>
|
2018-05-14 22:51:40 +08:00
|
|
|
|
for (; i < size; ++i)
|
2018-05-09 00:34:15 +08:00
|
|
|
|
_children[i]->_update();
|
2017-10-14 18:43:32 +08:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2018-05-19 00:00:12 +08:00
|
|
|
|
if (_autoUpdate && !Game::isPaused())
|
2018-02-04 21:24:27 +08:00
|
|
|
|
{
|
2018-05-19 00:00:12 +08:00
|
|
|
|
this->onUpdate();
|
2018-02-04 21:24:27 +08:00
|
|
|
|
}
|
2018-05-19 00:00:12 +08:00
|
|
|
|
this->_fixedUpdate();
|
2017-10-14 18:43:32 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-07 16:37:12 +08:00
|
|
|
|
void e2d::Node::_render()
|
2017-10-13 11:42:36 +08:00
|
|
|
|
{
|
2018-05-09 00:34:15 +08:00
|
|
|
|
if (!_visiable)
|
2018-01-30 16:45:38 +08:00
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-05-09 00:34:15 +08:00
|
|
|
|
if (!_children.empty())
|
2018-01-30 16:45:38 +08:00
|
|
|
|
{
|
2018-05-09 00:34:15 +08:00
|
|
|
|
size_t size = _children.size();
|
2018-01-30 16:45:38 +08:00
|
|
|
|
size_t i;
|
2018-05-14 22:51:40 +08:00
|
|
|
|
for (i = 0; i < size; ++i)
|
2018-01-30 16:45:38 +08:00
|
|
|
|
{
|
2018-05-09 00:34:15 +08:00
|
|
|
|
auto child = _children[i];
|
2018-01-30 16:45:38 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD> Order С<><D0A1><EFBFBD><EFBFBD><EFBFBD>Ľڵ<C4BD>
|
|
|
|
|
|
if (child->getOrder() < 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
child->_render();
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ת<><D7AA><EFBFBD><EFBFBD>Ⱦ<EFBFBD><C8BE><EFBFBD>Ķ<EFBFBD>ά<EFBFBD><CEAC><EFBFBD><EFBFBD>
|
2018-05-09 00:34:15 +08:00
|
|
|
|
Renderer::getRenderTarget()->SetTransform(_finalMatri);
|
2018-01-30 16:45:38 +08:00
|
|
|
|
// <20><>Ⱦ<EFBFBD><C8BE><EFBFBD><EFBFBD>
|
|
|
|
|
|
this->onRender();
|
|
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD>ʣ<EFBFBD><CAA3><EFBFBD>ڵ<EFBFBD>
|
2018-05-14 22:51:40 +08:00
|
|
|
|
for (; i < size; ++i)
|
2018-05-09 00:34:15 +08:00
|
|
|
|
_children[i]->_render();
|
2018-01-30 16:45:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
// ת<><D7AA><EFBFBD><EFBFBD>Ⱦ<EFBFBD><C8BE><EFBFBD>Ķ<EFBFBD>ά<EFBFBD><CEAC><EFBFBD><EFBFBD>
|
2018-05-09 00:34:15 +08:00
|
|
|
|
Renderer::getRenderTarget()->SetTransform(_finalMatri);
|
2018-01-30 16:45:38 +08:00
|
|
|
|
// <20><>Ⱦ<EFBFBD><C8BE><EFBFBD><EFBFBD>
|
|
|
|
|
|
this->onRender();
|
|
|
|
|
|
}
|
2017-10-12 23:34:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-04-02 23:01:38 +08:00
|
|
|
|
void e2d::Node::_drawCollider()
|
2017-10-29 23:48:32 +08:00
|
|
|
|
{
|
2018-04-02 23:01:38 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>ײ<EFBFBD><D7B2>
|
2018-05-09 00:34:15 +08:00
|
|
|
|
if (_collider && _collider->_visiable)
|
2017-10-29 23:48:32 +08:00
|
|
|
|
{
|
2018-05-09 00:34:15 +08:00
|
|
|
|
_collider->_render();
|
2017-10-29 23:48:32 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-04-02 23:01:38 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӽڵ<D3BD><DAB5>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>ײ<EFBFBD><D7B2>
|
2018-05-09 00:34:15 +08:00
|
|
|
|
for (auto child : _children)
|
2017-10-29 23:48:32 +08:00
|
|
|
|
{
|
2018-04-02 23:01:38 +08:00
|
|
|
|
child->_drawCollider();
|
2017-10-29 23:48:32 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-04-24 10:35:58 +08:00
|
|
|
|
void e2d::Node::_updateSelfTransform()
|
2017-10-15 23:58:39 +08:00
|
|
|
|
{
|
2017-11-09 18:22:41 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĵ<EFBFBD><C4B5><EFBFBD><EFBFBD><EFBFBD>
|
2018-05-09 00:34:15 +08:00
|
|
|
|
D2D1_POINT_2F pivot = { _width * _pivotX, _height * _pivotY };
|
2018-02-11 20:55:52 +08:00
|
|
|
|
// <20>任 Initial <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӽڵ㽫<DAB5><E3BDAB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>б任
|
2018-05-09 00:34:15 +08:00
|
|
|
|
_initialMatri = D2D1::Matrix3x2F::Scale(
|
|
|
|
|
|
_scaleX,
|
|
|
|
|
|
_scaleY,
|
2017-11-04 15:38:41 +08:00
|
|
|
|
pivot
|
2017-10-15 23:58:39 +08:00
|
|
|
|
) * D2D1::Matrix3x2F::Skew(
|
2018-05-09 00:34:15 +08:00
|
|
|
|
_skewAngleX,
|
|
|
|
|
|
_skewAngleY,
|
2017-11-04 15:38:41 +08:00
|
|
|
|
pivot
|
2017-10-17 21:22:25 +08:00
|
|
|
|
) * D2D1::Matrix3x2F::Rotation(
|
2018-05-09 00:34:15 +08:00
|
|
|
|
_rotation,
|
2017-11-04 15:38:41 +08:00
|
|
|
|
pivot
|
2017-10-15 23:58:39 +08:00
|
|
|
|
) * D2D1::Matrix3x2F::Translation(
|
2018-05-09 00:34:15 +08:00
|
|
|
|
_posX,
|
|
|
|
|
|
_posY
|
2017-10-15 23:58:39 +08:00
|
|
|
|
);
|
2018-02-11 20:55:52 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĵ<EFBFBD><C4B5>任 Final <20><><EFBFBD><EFBFBD>
|
2018-05-09 00:34:15 +08:00
|
|
|
|
_finalMatri = _initialMatri * D2D1::Matrix3x2F::Translation(-pivot.x, -pivot.y);
|
2017-11-09 18:22:41 +08:00
|
|
|
|
// <20><EFBFBD><CDB8>ڵ<EFBFBD><DAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2018-05-09 00:34:15 +08:00
|
|
|
|
if (!_positionFixed && _parent)
|
2017-11-09 18:22:41 +08:00
|
|
|
|
{
|
2018-05-09 00:34:15 +08:00
|
|
|
|
_initialMatri = _initialMatri * _parent->_initialMatri;
|
|
|
|
|
|
_finalMatri = _finalMatri * _parent->_initialMatri;
|
2017-11-09 18:22:41 +08:00
|
|
|
|
}
|
2017-10-15 23:58:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-04-24 10:35:58 +08:00
|
|
|
|
void e2d::Node::_updateTransform()
|
2017-10-12 23:34:13 +08:00
|
|
|
|
{
|
2017-10-26 17:17:30 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD><D7AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2018-04-24 10:35:58 +08:00
|
|
|
|
_updateSelfTransform();
|
2018-04-02 23:01:38 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ײ<EFBFBD><D7B2>Ҳ<EFBFBD><D2B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧת<D3A6><D7AA>
|
2018-05-09 00:34:15 +08:00
|
|
|
|
if (_collider)
|
2017-10-29 23:48:32 +08:00
|
|
|
|
{
|
2018-05-09 00:34:15 +08:00
|
|
|
|
_collider->_transform();
|
2017-10-29 23:48:32 +08:00
|
|
|
|
}
|
|
|
|
|
|
// <20><>־<EFBFBD><D6BE>ִ<EFBFBD>й<EFBFBD><D0B9>任
|
2018-05-09 00:34:15 +08:00
|
|
|
|
_needTransform = false;
|
2018-04-24 10:35:58 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>ӽڵ<D3BD><DAB5>µ<EFBFBD><C2B5><EFBFBD><EFBFBD>нڵ<D0BD>
|
2018-05-09 00:34:15 +08:00
|
|
|
|
for (auto child : this->_children)
|
2017-10-15 23:58:39 +08:00
|
|
|
|
{
|
2018-04-24 10:35:58 +08:00
|
|
|
|
child->_updateTransform();
|
2017-10-15 23:58:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-10-14 18:43:32 +08:00
|
|
|
|
|
2018-04-24 10:35:58 +08:00
|
|
|
|
void e2d::Node::_updateOpacity()
|
2017-10-15 23:58:39 +08:00
|
|
|
|
{
|
2018-05-09 00:34:15 +08:00
|
|
|
|
if (_parent)
|
2018-04-24 10:35:58 +08:00
|
|
|
|
{
|
2018-05-09 00:34:15 +08:00
|
|
|
|
_displayOpacity = _realOpacity * _parent->_displayOpacity;
|
2018-04-24 10:35:58 +08:00
|
|
|
|
}
|
2018-05-09 00:34:15 +08:00
|
|
|
|
for (auto child : _children)
|
2017-10-15 23:58:39 +08:00
|
|
|
|
{
|
2018-04-24 10:35:58 +08:00
|
|
|
|
child->_updateOpacity();
|
2017-10-12 23:34:13 +08:00
|
|
|
|
}
|
2017-10-14 18:43:32 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-05-19 00:00:12 +08:00
|
|
|
|
void e2d::Node::_fixedUpdate()
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-07 16:37:12 +08:00
|
|
|
|
bool e2d::Node::isVisiable() const
|
2017-10-14 18:43:32 +08:00
|
|
|
|
{
|
2018-05-09 00:34:15 +08:00
|
|
|
|
return _visiable;
|
2017-10-14 18:43:32 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-07 16:37:12 +08:00
|
|
|
|
e2d::String e2d::Node::getName() const
|
2017-10-17 21:22:25 +08:00
|
|
|
|
{
|
2018-05-08 20:03:29 +08:00
|
|
|
|
return _name;
|
2017-10-17 21:22:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-03-31 18:12:01 +08:00
|
|
|
|
unsigned int e2d::Node::getHashName() const
|
|
|
|
|
|
{
|
2018-05-09 00:34:15 +08:00
|
|
|
|
return _hashName;
|
2018-03-31 18:12:01 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-27 21:07:43 +08:00
|
|
|
|
double e2d::Node::getPosX() const
|
2017-10-17 21:22:25 +08:00
|
|
|
|
{
|
2018-05-09 00:34:15 +08:00
|
|
|
|
return _posX;
|
2017-10-17 21:22:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-27 21:07:43 +08:00
|
|
|
|
double e2d::Node::getPosY() const
|
2017-10-15 02:46:24 +08:00
|
|
|
|
{
|
2018-05-09 00:34:15 +08:00
|
|
|
|
return _posY;
|
2017-10-15 02:46:24 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-07 16:37:12 +08:00
|
|
|
|
e2d::Point e2d::Node::getPos() const
|
2017-10-15 02:46:24 +08:00
|
|
|
|
{
|
2018-05-09 00:34:15 +08:00
|
|
|
|
return Point(_posX, _posY);
|
2017-10-15 02:46:24 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-27 21:07:43 +08:00
|
|
|
|
double e2d::Node::getWidth() const
|
2017-10-14 18:43:32 +08:00
|
|
|
|
{
|
2018-05-09 00:34:15 +08:00
|
|
|
|
return _width * _scaleX;
|
2017-10-14 18:43:32 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-27 21:07:43 +08:00
|
|
|
|
double e2d::Node::getHeight() const
|
2017-10-14 18:43:32 +08:00
|
|
|
|
{
|
2018-05-09 00:34:15 +08:00
|
|
|
|
return _height * _scaleY;
|
2017-10-17 21:22:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-27 21:07:43 +08:00
|
|
|
|
double e2d::Node::getRealWidth() const
|
2017-10-17 21:22:25 +08:00
|
|
|
|
{
|
2018-05-09 00:34:15 +08:00
|
|
|
|
return _width;
|
2017-10-17 21:22:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-27 21:07:43 +08:00
|
|
|
|
double e2d::Node::getRealHeight() const
|
2017-10-17 21:22:25 +08:00
|
|
|
|
{
|
2018-05-09 00:34:15 +08:00
|
|
|
|
return _height;
|
2017-10-17 21:22:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-07 16:37:12 +08:00
|
|
|
|
e2d::Size e2d::Node::getRealSize() const
|
2017-10-17 21:22:25 +08:00
|
|
|
|
{
|
2018-05-09 00:34:15 +08:00
|
|
|
|
return Size(_width, _height);
|
2017-10-17 21:22:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-27 21:07:43 +08:00
|
|
|
|
double e2d::Node::getPivotX() const
|
2017-10-26 17:17:30 +08:00
|
|
|
|
{
|
2018-05-09 00:34:15 +08:00
|
|
|
|
return _pivotX;
|
2017-10-26 17:17:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-27 21:07:43 +08:00
|
|
|
|
double e2d::Node::getPivotY() const
|
2017-10-26 17:17:30 +08:00
|
|
|
|
{
|
2018-05-09 00:34:15 +08:00
|
|
|
|
return _pivotY;
|
2017-10-26 17:17:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-07 16:37:12 +08:00
|
|
|
|
e2d::Size e2d::Node::getSize() const
|
2017-10-17 21:22:25 +08:00
|
|
|
|
{
|
2018-02-07 16:37:12 +08:00
|
|
|
|
return Size(getWidth(), getHeight());
|
2017-10-12 23:34:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-27 21:07:43 +08:00
|
|
|
|
double e2d::Node::getScaleX() const
|
2017-10-12 23:34:13 +08:00
|
|
|
|
{
|
2018-05-09 00:34:15 +08:00
|
|
|
|
return _scaleX;
|
2017-10-12 23:34:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-27 21:07:43 +08:00
|
|
|
|
double e2d::Node::getScaleY() const
|
2017-10-12 23:34:13 +08:00
|
|
|
|
{
|
2018-05-09 00:34:15 +08:00
|
|
|
|
return _scaleY;
|
2017-10-12 23:34:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-27 21:07:43 +08:00
|
|
|
|
double e2d::Node::getSkewX() const
|
2017-10-12 23:34:13 +08:00
|
|
|
|
{
|
2018-05-09 00:34:15 +08:00
|
|
|
|
return _skewAngleX;
|
2017-10-12 23:34:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-27 21:07:43 +08:00
|
|
|
|
double e2d::Node::getSkewY() const
|
2017-10-12 23:34:13 +08:00
|
|
|
|
{
|
2018-05-09 00:34:15 +08:00
|
|
|
|
return _skewAngleY;
|
2017-10-12 23:34:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-27 21:07:43 +08:00
|
|
|
|
double e2d::Node::getRotation() const
|
2017-10-12 23:34:13 +08:00
|
|
|
|
{
|
2018-05-09 00:34:15 +08:00
|
|
|
|
return _rotation;
|
2017-10-12 23:34:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-27 21:07:43 +08:00
|
|
|
|
double e2d::Node::getOpacity() const
|
2017-10-12 23:34:13 +08:00
|
|
|
|
{
|
2018-05-09 00:34:15 +08:00
|
|
|
|
return _realOpacity;
|
2017-10-15 02:46:24 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-05-17 15:22:14 +08:00
|
|
|
|
e2d::Node::Property e2d::Node::getProperty() const
|
2018-04-21 18:42:07 +08:00
|
|
|
|
{
|
2018-05-17 15:22:14 +08:00
|
|
|
|
Property prop;
|
2018-05-09 00:34:15 +08:00
|
|
|
|
prop.visable = _visiable;
|
|
|
|
|
|
prop.posX = _posX;
|
|
|
|
|
|
prop.posY = _posY;
|
|
|
|
|
|
prop.width = _width;
|
|
|
|
|
|
prop.height = _height;
|
|
|
|
|
|
prop.opacity = _realOpacity;
|
|
|
|
|
|
prop.pivotX = _pivotX;
|
|
|
|
|
|
prop.pivotY = _pivotY;
|
|
|
|
|
|
prop.scaleX = _scaleX;
|
|
|
|
|
|
prop.scaleY = _scaleY;
|
|
|
|
|
|
prop.rotation = _rotation;
|
|
|
|
|
|
prop.skewAngleX = _skewAngleX;
|
|
|
|
|
|
prop.skewAngleY = _skewAngleY;
|
2018-04-21 18:42:07 +08:00
|
|
|
|
return prop;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-04-02 23:01:38 +08:00
|
|
|
|
e2d::Collider * e2d::Node::getCollider() const
|
2018-02-03 22:04:43 +08:00
|
|
|
|
{
|
2018-05-09 00:34:15 +08:00
|
|
|
|
return _collider;
|
2018-02-03 22:04:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-07 16:37:12 +08:00
|
|
|
|
int e2d::Node::getOrder() const
|
2017-10-15 02:46:24 +08:00
|
|
|
|
{
|
2018-05-08 17:40:36 +08:00
|
|
|
|
return _nOrder;
|
2017-10-15 02:46:24 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-07 16:37:12 +08:00
|
|
|
|
void e2d::Node::setOrder(int order)
|
2017-10-15 02:46:24 +08:00
|
|
|
|
{
|
2018-05-08 17:40:36 +08:00
|
|
|
|
_nOrder = order;
|
2017-10-12 23:34:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-27 21:07:43 +08:00
|
|
|
|
void e2d::Node::setPosX(double x)
|
2017-10-17 21:22:25 +08:00
|
|
|
|
{
|
2018-05-09 00:34:15 +08:00
|
|
|
|
this->setPos(x, _posY);
|
2017-10-17 21:22:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-27 21:07:43 +08:00
|
|
|
|
void e2d::Node::setPosY(double y)
|
2017-10-12 23:34:13 +08:00
|
|
|
|
{
|
2018-05-09 00:34:15 +08:00
|
|
|
|
this->setPos(_posX, y);
|
2017-10-12 23:34:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-07 16:37:12 +08:00
|
|
|
|
void e2d::Node::setPos(const Point & p)
|
2017-10-12 23:34:13 +08:00
|
|
|
|
{
|
2017-10-17 21:22:25 +08:00
|
|
|
|
this->setPos(p.x, p.y);
|
2017-10-12 23:34:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-27 21:07:43 +08:00
|
|
|
|
void e2d::Node::setPos(double x, double y)
|
2017-10-12 23:34:13 +08:00
|
|
|
|
{
|
2018-05-09 00:34:15 +08:00
|
|
|
|
if (_posX == x && _posY == y)
|
2017-10-14 18:43:32 +08:00
|
|
|
|
return;
|
|
|
|
|
|
|
2018-05-09 00:34:15 +08:00
|
|
|
|
_posX = float(x);
|
|
|
|
|
|
_posY = float(y);
|
|
|
|
|
|
_needTransform = true;
|
2017-10-12 23:34:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-05-07 17:15:57 +08:00
|
|
|
|
void e2d::Node::setPosFixed(bool fixed)
|
|
|
|
|
|
{
|
2018-05-09 00:34:15 +08:00
|
|
|
|
if (_positionFixed == fixed)
|
2018-05-07 17:15:57 +08:00
|
|
|
|
return;
|
|
|
|
|
|
|
2018-05-09 00:34:15 +08:00
|
|
|
|
_positionFixed = fixed;
|
|
|
|
|
|
_needTransform = true;
|
2018-05-07 17:15:57 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-27 21:07:43 +08:00
|
|
|
|
void e2d::Node::movePosX(double x)
|
2017-11-03 12:51:01 +08:00
|
|
|
|
{
|
|
|
|
|
|
this->movePos(x, 0);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-27 21:07:43 +08:00
|
|
|
|
void e2d::Node::movePosY(double y)
|
2017-11-03 12:51:01 +08:00
|
|
|
|
{
|
|
|
|
|
|
this->movePos(0, y);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-27 21:07:43 +08:00
|
|
|
|
void e2d::Node::movePos(double x, double y)
|
2017-10-12 23:34:13 +08:00
|
|
|
|
{
|
2018-05-09 00:34:15 +08:00
|
|
|
|
this->setPos(_posX + x, _posY + y);
|
2017-10-17 21:22:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-07 16:37:12 +08:00
|
|
|
|
void e2d::Node::movePos(const Vector & v)
|
2017-10-17 21:22:25 +08:00
|
|
|
|
{
|
2017-11-03 12:51:01 +08:00
|
|
|
|
this->movePos(v.x, v.y);
|
2017-10-12 23:34:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-27 21:07:43 +08:00
|
|
|
|
void e2d::Node::setScaleX(double scaleX)
|
2017-10-12 23:34:13 +08:00
|
|
|
|
{
|
2018-05-09 00:34:15 +08:00
|
|
|
|
this->setScale(scaleX, _scaleY);
|
2017-10-12 23:34:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-27 21:07:43 +08:00
|
|
|
|
void e2d::Node::setScaleY(double scaleY)
|
2017-10-12 23:34:13 +08:00
|
|
|
|
{
|
2018-05-09 00:34:15 +08:00
|
|
|
|
this->setScale(_scaleX, scaleY);
|
2017-10-12 23:34:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-27 21:07:43 +08:00
|
|
|
|
void e2d::Node::setScale(double scale)
|
2017-10-12 23:34:13 +08:00
|
|
|
|
{
|
2017-10-15 02:46:24 +08:00
|
|
|
|
this->setScale(scale, scale);
|
2017-10-12 23:34:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-27 21:07:43 +08:00
|
|
|
|
void e2d::Node::setScale(double scaleX, double scaleY)
|
2017-10-12 23:34:13 +08:00
|
|
|
|
{
|
2018-05-09 00:34:15 +08:00
|
|
|
|
if (_scaleX == scaleX && _scaleY == scaleY)
|
2017-10-15 02:46:24 +08:00
|
|
|
|
return;
|
|
|
|
|
|
|
2018-05-09 00:34:15 +08:00
|
|
|
|
_scaleX = float(scaleX);
|
|
|
|
|
|
_scaleY = float(scaleY);
|
|
|
|
|
|
_needTransform = true;
|
2017-10-12 23:34:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-27 21:07:43 +08:00
|
|
|
|
void e2d::Node::setSkewX(double angleX)
|
2017-10-12 23:34:13 +08:00
|
|
|
|
{
|
2018-05-09 00:34:15 +08:00
|
|
|
|
this->setSkew(angleX, _skewAngleY);
|
2017-10-12 23:34:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-27 21:07:43 +08:00
|
|
|
|
void e2d::Node::setSkewY(double angleY)
|
2017-10-12 23:34:13 +08:00
|
|
|
|
{
|
2018-05-09 00:34:15 +08:00
|
|
|
|
this->setSkew(_skewAngleX, angleY);
|
2017-10-12 23:34:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-27 21:07:43 +08:00
|
|
|
|
void e2d::Node::setSkew(double angleX, double angleY)
|
2017-10-12 23:34:13 +08:00
|
|
|
|
{
|
2018-05-09 00:34:15 +08:00
|
|
|
|
if (_skewAngleX == angleX && _skewAngleY == angleY)
|
2017-10-15 02:46:24 +08:00
|
|
|
|
return;
|
|
|
|
|
|
|
2018-05-09 00:34:15 +08:00
|
|
|
|
_skewAngleX = float(angleX);
|
|
|
|
|
|
_skewAngleY = float(angleY);
|
|
|
|
|
|
_needTransform = true;
|
2017-10-15 02:46:24 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-27 21:07:43 +08:00
|
|
|
|
void e2d::Node::setRotation(double angle)
|
2017-10-15 02:46:24 +08:00
|
|
|
|
{
|
2018-05-09 00:34:15 +08:00
|
|
|
|
if (_rotation == angle)
|
2017-10-15 02:46:24 +08:00
|
|
|
|
return;
|
|
|
|
|
|
|
2018-05-09 00:34:15 +08:00
|
|
|
|
_rotation = float(angle);
|
|
|
|
|
|
_needTransform = true;
|
2017-10-15 02:46:24 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-27 21:07:43 +08:00
|
|
|
|
void e2d::Node::setOpacity(double opacity)
|
2017-10-15 02:46:24 +08:00
|
|
|
|
{
|
2018-05-09 00:34:15 +08:00
|
|
|
|
if (_realOpacity == opacity)
|
2017-10-15 23:58:39 +08:00
|
|
|
|
return;
|
|
|
|
|
|
|
2018-05-09 00:34:15 +08:00
|
|
|
|
_displayOpacity = _realOpacity = min(max(float(opacity), 0), 1);
|
2017-10-21 19:09:31 +08:00
|
|
|
|
// <20><><EFBFBD>½ڵ<C2BD><EFBFBD><CDB8><EFBFBD><EFBFBD>
|
2018-04-24 10:35:58 +08:00
|
|
|
|
_updateOpacity();
|
2017-10-15 23:58:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-27 21:07:43 +08:00
|
|
|
|
void e2d::Node::setPivotX(double pivotX)
|
2017-10-15 23:58:39 +08:00
|
|
|
|
{
|
2018-05-09 00:34:15 +08:00
|
|
|
|
this->setPivot(pivotX, _pivotY);
|
2017-10-15 23:58:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-27 21:07:43 +08:00
|
|
|
|
void e2d::Node::setPivotY(double pivotY)
|
2017-10-15 23:58:39 +08:00
|
|
|
|
{
|
2018-05-09 00:34:15 +08:00
|
|
|
|
this->setPivot(_pivotX, pivotY);
|
2017-10-15 23:58:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-27 21:07:43 +08:00
|
|
|
|
void e2d::Node::setPivot(double pivotX, double pivotY)
|
2017-10-15 23:58:39 +08:00
|
|
|
|
{
|
2018-05-09 00:34:15 +08:00
|
|
|
|
if (_pivotX == pivotX && _pivotY == pivotY)
|
2017-10-15 23:58:39 +08:00
|
|
|
|
return;
|
|
|
|
|
|
|
2018-05-09 00:34:15 +08:00
|
|
|
|
_pivotX = min(max(float(pivotX), 0), 1);
|
|
|
|
|
|
_pivotY = min(max(float(pivotY), 0), 1);
|
|
|
|
|
|
_needTransform = true;
|
2017-10-12 23:34:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-03-01 19:28:22 +08:00
|
|
|
|
void e2d::Node::setWidth(double width)
|
|
|
|
|
|
{
|
2018-05-09 00:34:15 +08:00
|
|
|
|
this->setSize(width, _height);
|
2018-03-01 19:28:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void e2d::Node::setHeight(double height)
|
|
|
|
|
|
{
|
2018-05-09 00:34:15 +08:00
|
|
|
|
this->setSize(_width, height);
|
2018-03-01 19:28:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void e2d::Node::setSize(double width, double height)
|
|
|
|
|
|
{
|
2018-05-09 00:34:15 +08:00
|
|
|
|
if (_width == width && _height == height)
|
2018-03-01 19:28:22 +08:00
|
|
|
|
return;
|
|
|
|
|
|
|
2018-05-09 00:34:15 +08:00
|
|
|
|
_width = float(width);
|
|
|
|
|
|
_height = float(height);
|
|
|
|
|
|
_needTransform = true;
|
2018-03-01 19:28:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void e2d::Node::setSize(Size size)
|
|
|
|
|
|
{
|
|
|
|
|
|
this->setSize(size.width, size.height);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-05-17 15:22:14 +08:00
|
|
|
|
void e2d::Node::setProperty(Property prop)
|
2018-04-21 18:42:07 +08:00
|
|
|
|
{
|
|
|
|
|
|
this->setVisiable(prop.visable);
|
|
|
|
|
|
this->setPos(prop.posX, prop.posY);
|
|
|
|
|
|
this->setSize(prop.width, prop.height);
|
|
|
|
|
|
this->setOpacity(prop.opacity);
|
|
|
|
|
|
this->setPivot(prop.pivotX, prop.pivotY);
|
|
|
|
|
|
this->setScale(prop.scaleX, prop.scaleY);
|
|
|
|
|
|
this->setRotation(prop.rotation);
|
|
|
|
|
|
this->setSkew(prop.skewAngleX, prop.skewAngleY);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-05-17 15:22:14 +08:00
|
|
|
|
void e2d::Node::setCollider(Collider::Type type)
|
2018-03-31 11:59:51 +08:00
|
|
|
|
{
|
2018-05-17 15:22:14 +08:00
|
|
|
|
switch (type)
|
2018-03-31 11:59:51 +08:00
|
|
|
|
{
|
2018-05-17 15:22:14 +08:00
|
|
|
|
case Collider::Type::RECT:
|
2018-03-31 11:59:51 +08:00
|
|
|
|
{
|
2018-05-19 01:10:37 +08:00
|
|
|
|
this->setCollider(GC::create<ColliderRect>(this));
|
2018-03-31 11:59:51 +08:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-05-17 15:22:14 +08:00
|
|
|
|
case Collider::Type::CIRCLE:
|
2018-03-31 11:59:51 +08:00
|
|
|
|
{
|
2018-05-19 01:10:37 +08:00
|
|
|
|
this->setCollider(GC::create<ColliderCircle>(this));
|
2018-03-31 11:59:51 +08:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-05-17 15:22:14 +08:00
|
|
|
|
case Collider::Type::ELLIPSE:
|
2018-03-31 11:59:51 +08:00
|
|
|
|
{
|
2018-05-19 01:10:37 +08:00
|
|
|
|
this->setCollider(GC::create<ColliderEllipse>(this));
|
2018-03-31 11:59:51 +08:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-04-02 23:01:38 +08:00
|
|
|
|
void e2d::Node::setCollider(Collider * pCollider)
|
2017-10-26 17:17:30 +08:00
|
|
|
|
{
|
2018-04-02 23:01:38 +08:00
|
|
|
|
// ɾ<><C9BE><EFBFBD>ɵ<EFBFBD><C9B5><EFBFBD>ײ<EFBFBD><D7B2>
|
2018-05-09 00:34:15 +08:00
|
|
|
|
ColliderManager::__removeCollider(_collider);
|
2018-04-02 23:01:38 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD><C2B5><EFBFBD>ײ<EFBFBD><D7B2>
|
|
|
|
|
|
ColliderManager::__addCollider(pCollider);
|
2017-10-29 23:48:32 +08:00
|
|
|
|
|
2018-04-02 23:01:38 +08:00
|
|
|
|
if (pCollider)
|
2017-10-28 18:48:21 +08:00
|
|
|
|
{
|
2017-10-29 23:48:32 +08:00
|
|
|
|
// ˫<><CBAB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2018-05-09 00:34:15 +08:00
|
|
|
|
this->_collider = pCollider;
|
|
|
|
|
|
pCollider->_parentNode = this;
|
2017-10-28 18:48:21 +08:00
|
|
|
|
}
|
2017-10-29 23:48:32 +08:00
|
|
|
|
else
|
2017-10-28 18:48:21 +08:00
|
|
|
|
{
|
2018-05-09 00:34:15 +08:00
|
|
|
|
this->_collider = nullptr;
|
2017-10-28 18:48:21 +08:00
|
|
|
|
}
|
2017-10-26 17:17:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-05-07 15:48:06 +08:00
|
|
|
|
void e2d::Node::addColliableName(const String& collliderName)
|
2018-03-31 18:12:01 +08:00
|
|
|
|
{
|
|
|
|
|
|
unsigned int hash = collliderName.getHashCode();
|
2018-05-09 00:34:15 +08:00
|
|
|
|
_colliders.insert(hash);
|
2018-03-31 18:12:01 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-05-10 17:02:18 +08:00
|
|
|
|
void e2d::Node::addColliableName(const std::vector<String>& colliderNames)
|
2018-03-31 18:12:01 +08:00
|
|
|
|
{
|
2018-05-10 00:58:43 +08:00
|
|
|
|
for (const auto &name : colliderNames)
|
2018-03-31 18:12:01 +08:00
|
|
|
|
{
|
2018-04-02 23:01:38 +08:00
|
|
|
|
this->addColliableName(name);
|
2018-03-31 18:12:01 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-05-07 15:48:06 +08:00
|
|
|
|
void e2d::Node::removeColliableName(const String& collliderName)
|
2018-03-31 18:12:01 +08:00
|
|
|
|
{
|
|
|
|
|
|
unsigned int hash = collliderName.getHashCode();
|
2018-05-09 00:34:15 +08:00
|
|
|
|
_colliders.erase(hash);
|
2018-03-31 18:12:01 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-07 16:37:12 +08:00
|
|
|
|
void e2d::Node::addChild(Node * child, int order /* = 0 */)
|
2017-10-14 11:40:47 +08:00
|
|
|
|
{
|
2018-02-07 16:37:12 +08:00
|
|
|
|
WARN_IF(child == nullptr, "Node::addChild NULL pointer exception.");
|
2017-10-14 11:40:47 +08:00
|
|
|
|
|
|
|
|
|
|
if (child)
|
|
|
|
|
|
{
|
2018-05-09 00:34:15 +08:00
|
|
|
|
ASSERT(child->_parent == nullptr, "Node already added. It can't be added again!");
|
2018-02-03 22:04:43 +08:00
|
|
|
|
|
2018-02-07 16:37:12 +08:00
|
|
|
|
for (Node * parent = this; parent != nullptr; parent = parent->getParent())
|
2017-10-14 11:40:47 +08:00
|
|
|
|
{
|
2018-02-07 16:37:12 +08:00
|
|
|
|
ASSERT(child != parent, "A Node cannot be the child of his own children!");
|
2017-10-14 11:40:47 +08:00
|
|
|
|
}
|
2017-10-14 18:43:32 +08:00
|
|
|
|
|
2018-05-09 00:34:15 +08:00
|
|
|
|
_children.push_back(child);
|
2017-10-14 18:43:32 +08:00
|
|
|
|
|
|
|
|
|
|
child->setOrder(order);
|
|
|
|
|
|
|
|
|
|
|
|
child->retain();
|
|
|
|
|
|
|
2018-05-09 00:34:15 +08:00
|
|
|
|
child->_parent = this;
|
2017-10-15 23:58:39 +08:00
|
|
|
|
|
2018-05-09 00:34:15 +08:00
|
|
|
|
if (this->_parentScene)
|
2017-10-17 21:22:25 +08:00
|
|
|
|
{
|
2018-05-09 00:34:15 +08:00
|
|
|
|
child->_setParentScene(this->_parentScene);
|
2017-10-17 21:22:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-11-09 18:22:41 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>ӽڵ<D3BD><EFBFBD><CDB8><EFBFBD><EFBFBD>
|
2018-04-24 10:35:58 +08:00
|
|
|
|
child->_updateOpacity();
|
2017-11-09 18:22:41 +08:00
|
|
|
|
// <20><><EFBFBD>½ڵ<C2BD>ת<EFBFBD><D7AA>
|
2018-05-09 00:34:15 +08:00
|
|
|
|
child->_needTransform = true;
|
2017-11-09 18:22:41 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>ӽڵ<D3BD><DAB5><EFBFBD><EFBFBD><EFBFBD>
|
2018-05-09 00:34:15 +08:00
|
|
|
|
_needSort = true;
|
2017-10-14 11:40:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-05-10 17:02:18 +08:00
|
|
|
|
void e2d::Node::addChild(const std::vector<Node*>& nodes, int order)
|
2018-03-31 18:12:01 +08:00
|
|
|
|
{
|
2018-05-10 17:02:18 +08:00
|
|
|
|
for (auto node : nodes)
|
2018-03-31 18:12:01 +08:00
|
|
|
|
{
|
|
|
|
|
|
this->addChild(node, order);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-07 16:37:12 +08:00
|
|
|
|
e2d::Node * e2d::Node::getParent() const
|
2017-10-12 23:34:13 +08:00
|
|
|
|
{
|
2018-05-09 00:34:15 +08:00
|
|
|
|
return _parent;
|
2017-10-12 23:34:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-07 16:37:12 +08:00
|
|
|
|
e2d::Scene * e2d::Node::getParentScene() const
|
2017-10-12 23:34:13 +08:00
|
|
|
|
{
|
2018-05-09 00:34:15 +08:00
|
|
|
|
return _parentScene;
|
2017-10-12 23:34:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-05-07 15:48:06 +08:00
|
|
|
|
std::vector<e2d::Node*> e2d::Node::getChildren(const String& name) const
|
2017-10-14 11:40:47 +08:00
|
|
|
|
{
|
2018-03-11 23:56:40 +08:00
|
|
|
|
std::vector<Node*> vChildren;
|
2018-03-01 23:47:42 +08:00
|
|
|
|
unsigned int hash = name.getHashCode();
|
2017-10-14 11:40:47 +08:00
|
|
|
|
|
2018-05-09 00:34:15 +08:00
|
|
|
|
for (auto child : _children)
|
2017-10-14 11:40:47 +08:00
|
|
|
|
{
|
|
|
|
|
|
// <20><>ͬ<EFBFBD><CDAC><EFBFBD><EFBFBD><EFBFBD>ƿ<EFBFBD><C6BF>ܻ<EFBFBD><DCBB><EFBFBD><EFBFBD><EFBFBD>ͬ<EFBFBD><CDAC> Hash ֵ<><D6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȱȽ<C8B1> Hash <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ٶ<EFBFBD>
|
2018-05-09 00:34:15 +08:00
|
|
|
|
if (child->_hashName == hash && child->_name == name)
|
2018-03-11 23:56:40 +08:00
|
|
|
|
{
|
|
|
|
|
|
vChildren.push_back(child);
|
|
|
|
|
|
}
|
2017-10-14 11:40:47 +08:00
|
|
|
|
}
|
2018-03-11 23:56:40 +08:00
|
|
|
|
return std::move(vChildren);
|
2017-10-14 11:40:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-05-07 15:48:06 +08:00
|
|
|
|
e2d::Node * e2d::Node::getChild(const String& name) const
|
2018-04-24 13:28:21 +08:00
|
|
|
|
{
|
|
|
|
|
|
unsigned int hash = name.getHashCode();
|
|
|
|
|
|
|
2018-05-09 00:34:15 +08:00
|
|
|
|
for (auto child : _children)
|
2018-04-24 13:28:21 +08:00
|
|
|
|
{
|
|
|
|
|
|
// <20><>ͬ<EFBFBD><CDAC><EFBFBD><EFBFBD><EFBFBD>ƿ<EFBFBD><C6BF>ܻ<EFBFBD><DCBB><EFBFBD><EFBFBD><EFBFBD>ͬ<EFBFBD><CDAC> Hash ֵ<><D6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȱȽ<C8B1> Hash <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ٶ<EFBFBD>
|
2018-05-09 00:34:15 +08:00
|
|
|
|
if (child->_hashName == hash && child->_name == name)
|
2018-04-24 13:28:21 +08:00
|
|
|
|
{
|
|
|
|
|
|
return child;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return nullptr;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-05-10 14:16:36 +08:00
|
|
|
|
const std::vector<e2d::Node*>& e2d::Node::getAllChildren() const
|
2018-02-03 22:04:43 +08:00
|
|
|
|
{
|
2018-05-09 00:34:15 +08:00
|
|
|
|
return _children;
|
2018-03-11 23:56:40 +08:00
|
|
|
|
}
|
2018-02-03 22:04:43 +08:00
|
|
|
|
|
2018-03-11 23:56:40 +08:00
|
|
|
|
int e2d::Node::getChildrenCount() const
|
|
|
|
|
|
{
|
2018-05-09 00:34:15 +08:00
|
|
|
|
return static_cast<int>(_children.size());
|
2018-02-03 22:04:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-07 16:37:12 +08:00
|
|
|
|
void e2d::Node::removeFromParent()
|
2017-10-14 11:40:47 +08:00
|
|
|
|
{
|
2018-05-09 00:34:15 +08:00
|
|
|
|
if (_parent)
|
2017-10-14 18:43:32 +08:00
|
|
|
|
{
|
2018-05-09 00:34:15 +08:00
|
|
|
|
_parent->removeChild(this);
|
2017-10-14 18:43:32 +08:00
|
|
|
|
}
|
2017-10-14 11:40:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-07 16:37:12 +08:00
|
|
|
|
bool e2d::Node::removeChild(Node * child)
|
2017-10-14 11:40:47 +08:00
|
|
|
|
{
|
2018-02-07 16:37:12 +08:00
|
|
|
|
WARN_IF(child == nullptr, "Node::removeChildren NULL pointer exception.");
|
2017-10-14 18:43:32 +08:00
|
|
|
|
|
2018-05-09 00:34:15 +08:00
|
|
|
|
if (_children.empty())
|
2017-10-14 18:43:32 +08:00
|
|
|
|
{
|
2017-10-17 21:22:25 +08:00
|
|
|
|
return false;
|
2017-10-14 18:43:32 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (child)
|
|
|
|
|
|
{
|
2018-05-09 00:34:15 +08:00
|
|
|
|
size_t size = _children.size();
|
2018-05-14 22:51:40 +08:00
|
|
|
|
for (size_t i = 0; i < size; ++i)
|
2017-10-14 18:43:32 +08:00
|
|
|
|
{
|
2018-05-09 00:34:15 +08:00
|
|
|
|
if (_children[i] == child)
|
2017-10-14 18:43:32 +08:00
|
|
|
|
{
|
2018-05-09 00:34:15 +08:00
|
|
|
|
_children.erase(_children.begin() + i);
|
|
|
|
|
|
child->_parent = nullptr;
|
2018-02-03 22:04:43 +08:00
|
|
|
|
|
2018-05-09 00:34:15 +08:00
|
|
|
|
if (child->_parentScene)
|
2017-10-17 21:22:25 +08:00
|
|
|
|
{
|
|
|
|
|
|
child->_setParentScene(nullptr);
|
|
|
|
|
|
}
|
2018-02-03 22:04:43 +08:00
|
|
|
|
|
2017-10-14 18:43:32 +08:00
|
|
|
|
child->release();
|
2017-10-17 21:22:25 +08:00
|
|
|
|
return true;
|
2017-10-14 18:43:32 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-10-17 21:22:25 +08:00
|
|
|
|
return false;
|
2017-10-14 11:40:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-05-07 15:48:06 +08:00
|
|
|
|
void e2d::Node::removeChildren(const String& childName)
|
2017-10-14 11:40:47 +08:00
|
|
|
|
{
|
2018-02-07 16:37:12 +08:00
|
|
|
|
WARN_IF(childName.isEmpty(), "Invalid Node name.");
|
2017-10-14 18:43:32 +08:00
|
|
|
|
|
2018-05-09 00:34:15 +08:00
|
|
|
|
if (_children.empty())
|
2017-10-14 18:43:32 +08:00
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-10-17 21:22:25 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> Hash ֵ
|
2018-03-01 23:47:42 +08:00
|
|
|
|
unsigned int hash = childName.getHashCode();
|
2017-10-17 21:22:25 +08:00
|
|
|
|
|
2018-05-09 00:34:15 +08:00
|
|
|
|
size_t size = _children.size();
|
2018-05-14 22:51:40 +08:00
|
|
|
|
for (size_t i = 0; i < size; ++i)
|
2017-10-14 18:43:32 +08:00
|
|
|
|
{
|
2018-05-09 00:34:15 +08:00
|
|
|
|
auto child = _children[i];
|
|
|
|
|
|
if (child->_hashName == hash && child->_name == childName)
|
2017-10-14 18:43:32 +08:00
|
|
|
|
{
|
2018-05-09 00:34:15 +08:00
|
|
|
|
_children.erase(_children.begin() + i);
|
|
|
|
|
|
child->_parent = nullptr;
|
|
|
|
|
|
if (child->_parentScene)
|
2017-10-17 21:22:25 +08:00
|
|
|
|
{
|
|
|
|
|
|
child->_setParentScene(nullptr);
|
|
|
|
|
|
}
|
2017-10-14 18:43:32 +08:00
|
|
|
|
child->release();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-10-14 11:40:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-07 16:37:12 +08:00
|
|
|
|
void e2d::Node::clearAllChildren()
|
2017-10-17 21:22:25 +08:00
|
|
|
|
{
|
|
|
|
|
|
// <20><><EFBFBD>нڵ<D0BD><DAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ü<EFBFBD><C3BC><EFBFBD><EFBFBD><EFBFBD>һ
|
2018-05-09 00:34:15 +08:00
|
|
|
|
for (auto child : _children)
|
2017-10-17 21:22:25 +08:00
|
|
|
|
{
|
2018-02-03 22:04:43 +08:00
|
|
|
|
child->release();
|
2017-10-17 21:22:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
// <20><><EFBFBD>մ<EFBFBD><D5B4><EFBFBD><EFBFBD>ڵ<EFBFBD><DAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2018-05-09 00:34:15 +08:00
|
|
|
|
_children.clear();
|
2017-10-17 21:22:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-05-08 20:03:29 +08:00
|
|
|
|
void e2d::Node::runAction(Action * action)
|
2017-10-19 00:50:04 +08:00
|
|
|
|
{
|
2018-02-06 15:34:47 +08:00
|
|
|
|
if (this != action->getTarget())
|
|
|
|
|
|
{
|
2018-05-08 17:40:36 +08:00
|
|
|
|
ASSERT(action->getTarget() == nullptr, "The action has already got a target!");
|
|
|
|
|
|
ActionManager::start(action, this, false);
|
2018-02-06 15:34:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
else
|
2018-02-03 22:04:43 +08:00
|
|
|
|
{
|
2018-02-06 15:34:47 +08:00
|
|
|
|
action->reset();
|
2018-02-03 22:04:43 +08:00
|
|
|
|
}
|
2017-10-19 00:50:04 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-05-07 15:48:06 +08:00
|
|
|
|
void e2d::Node::resumeAction(const String& strActionName)
|
2017-10-19 12:47:36 +08:00
|
|
|
|
{
|
2018-03-13 13:13:26 +08:00
|
|
|
|
auto actions = ActionManager::get(strActionName);
|
2018-04-24 20:22:41 +08:00
|
|
|
|
for (auto action : actions)
|
2017-10-19 12:47:36 +08:00
|
|
|
|
{
|
2018-03-06 09:56:17 +08:00
|
|
|
|
if (action->getTarget() == this)
|
|
|
|
|
|
{
|
|
|
|
|
|
action->resume();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-05-07 15:48:06 +08:00
|
|
|
|
void e2d::Node::pauseAction(const String& strActionName)
|
2018-03-06 09:56:17 +08:00
|
|
|
|
{
|
2018-03-13 13:13:26 +08:00
|
|
|
|
auto actions = ActionManager::get(strActionName);
|
2018-04-24 20:22:41 +08:00
|
|
|
|
for (auto action : actions)
|
2018-03-06 09:56:17 +08:00
|
|
|
|
{
|
|
|
|
|
|
if (action->getTarget() == this)
|
|
|
|
|
|
{
|
|
|
|
|
|
action->pause();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-05-07 15:48:06 +08:00
|
|
|
|
void e2d::Node::stopAction(const String& strActionName)
|
2018-03-06 09:56:17 +08:00
|
|
|
|
{
|
2018-03-13 13:13:26 +08:00
|
|
|
|
auto actions = ActionManager::get(strActionName);
|
2018-04-24 20:22:41 +08:00
|
|
|
|
for (auto action : actions)
|
2018-03-06 09:56:17 +08:00
|
|
|
|
{
|
|
|
|
|
|
if (action->getTarget() == this)
|
|
|
|
|
|
{
|
|
|
|
|
|
action->stop();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-05-08 20:03:29 +08:00
|
|
|
|
e2d::Action * e2d::Node::getAction(const String& strActionName)
|
2018-03-06 09:56:17 +08:00
|
|
|
|
{
|
2018-03-13 13:13:26 +08:00
|
|
|
|
auto actions = ActionManager::get(strActionName);
|
2018-04-24 20:22:41 +08:00
|
|
|
|
for (auto action : actions)
|
2018-03-06 09:56:17 +08:00
|
|
|
|
{
|
|
|
|
|
|
if (action->getTarget() == this)
|
|
|
|
|
|
{
|
|
|
|
|
|
return action;
|
|
|
|
|
|
}
|
2017-10-19 12:47:36 +08:00
|
|
|
|
}
|
2018-03-06 09:56:17 +08:00
|
|
|
|
return nullptr;
|
2017-10-19 12:47:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-05-08 20:03:29 +08:00
|
|
|
|
std::vector<e2d::Action*> e2d::Node::getActions(const String& strActionName)
|
2017-10-19 12:47:36 +08:00
|
|
|
|
{
|
2018-05-08 20:03:29 +08:00
|
|
|
|
std::vector<Action*>::iterator iter;
|
2018-03-13 13:13:26 +08:00
|
|
|
|
auto actions = ActionManager::get(strActionName);
|
2018-03-06 09:56:17 +08:00
|
|
|
|
for (iter = actions.begin(); iter != actions.end();)
|
2017-10-19 12:47:36 +08:00
|
|
|
|
{
|
2018-03-06 09:56:17 +08:00
|
|
|
|
if ((*iter)->getTarget() != this)
|
|
|
|
|
|
{
|
|
|
|
|
|
iter = actions.erase(iter);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2018-05-14 22:51:40 +08:00
|
|
|
|
++iter;
|
2018-03-06 09:56:17 +08:00
|
|
|
|
}
|
2017-10-19 12:47:36 +08:00
|
|
|
|
}
|
2018-03-06 09:56:17 +08:00
|
|
|
|
return std::move(actions);
|
2017-10-19 12:47:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-03-07 20:14:58 +08:00
|
|
|
|
bool e2d::Node::isPointIn(Point point) const
|
2017-10-21 19:09:31 +08:00
|
|
|
|
{
|
2018-03-07 20:14:58 +08:00
|
|
|
|
BOOL ret = 0;
|
2018-04-02 23:01:38 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ײ<EFBFBD>壬<EFBFBD><E5A3AC><EFBFBD><EFBFBD>ײ<EFBFBD><D7B2><EFBFBD>ж<EFBFBD>
|
2018-05-09 00:34:15 +08:00
|
|
|
|
if (_collider)
|
2018-03-14 15:33:58 +08:00
|
|
|
|
{
|
2018-05-09 00:34:15 +08:00
|
|
|
|
_collider->getD2dGeometry()->FillContainsPoint(
|
2018-03-14 15:33:58 +08:00
|
|
|
|
D2D1::Point2F(
|
2018-05-09 00:34:15 +08:00
|
|
|
|
float(point.x),
|
|
|
|
|
|
float(point.y)),
|
|
|
|
|
|
_finalMatri,
|
2018-03-14 15:33:58 +08:00
|
|
|
|
&ret
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2018-04-02 23:01:38 +08:00
|
|
|
|
// Ϊ<>ڵ㴴<DAB5><E3B4B4>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>ײ<EFBFBD><D7B2>
|
2018-03-14 15:33:58 +08:00
|
|
|
|
ID2D1RectangleGeometry * rect;
|
|
|
|
|
|
Renderer::getID2D1Factory()->CreateRectangleGeometry(
|
2018-05-09 00:34:15 +08:00
|
|
|
|
D2D1::RectF(0, 0, _width, _height),
|
2018-03-14 15:33:58 +08:00
|
|
|
|
&rect
|
|
|
|
|
|
);
|
2018-04-02 23:01:38 +08:00
|
|
|
|
// <20>жϵ<D0B6><CFB5>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>ײ<EFBFBD><D7B2><EFBFBD><EFBFBD>
|
2018-03-14 15:33:58 +08:00
|
|
|
|
rect->FillContainsPoint(
|
|
|
|
|
|
D2D1::Point2F(
|
2018-05-09 00:34:15 +08:00
|
|
|
|
float(point.x),
|
|
|
|
|
|
float(point.y)),
|
|
|
|
|
|
_finalMatri,
|
2018-03-14 15:33:58 +08:00
|
|
|
|
&ret
|
|
|
|
|
|
);
|
2018-04-02 23:01:38 +08:00
|
|
|
|
// ɾ<><C9BE><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ײ<EFBFBD><D7B2>
|
2018-05-10 20:23:32 +08:00
|
|
|
|
SafeReleaseInterface(rect);
|
2018-03-14 15:33:58 +08:00
|
|
|
|
}
|
2018-03-07 20:14:58 +08:00
|
|
|
|
|
2017-11-09 18:22:41 +08:00
|
|
|
|
if (ret)
|
2017-10-21 19:09:31 +08:00
|
|
|
|
{
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
2018-03-11 23:56:40 +08:00
|
|
|
|
|
2017-10-21 19:09:31 +08:00
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-05-19 00:36:32 +08:00
|
|
|
|
bool e2d::Node::isOverlappedWith(const Node * node) const
|
2018-03-06 09:56:17 +08:00
|
|
|
|
{
|
2018-04-02 23:01:38 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ײ<EFBFBD>壬<EFBFBD><E5A3AC><EFBFBD><EFBFBD>ײ<EFBFBD><D7B2><EFBFBD>ж<EFBFBD>
|
2018-05-09 00:34:15 +08:00
|
|
|
|
if (this->_collider && node->_collider)
|
2018-03-11 23:56:40 +08:00
|
|
|
|
{
|
2018-05-17 15:22:14 +08:00
|
|
|
|
Collider::Relation relation = this->_collider->getRelationWith(node->_collider);
|
|
|
|
|
|
if ((relation != Collider::Relation::UNKNOWN) &&
|
2018-05-19 00:36:32 +08:00
|
|
|
|
(relation != Collider::Relation::DISJOIN))
|
2018-03-11 23:56:40 +08:00
|
|
|
|
{
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-03-14 15:33:58 +08:00
|
|
|
|
else
|
|
|
|
|
|
{
|
2018-04-02 23:01:38 +08:00
|
|
|
|
// Ϊ<>ڵ㴴<DAB5><E3B4B4>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>ײ<EFBFBD><D7B2>
|
2018-03-14 15:33:58 +08:00
|
|
|
|
ID2D1RectangleGeometry * pRect1;
|
|
|
|
|
|
ID2D1RectangleGeometry * pRect2;
|
2018-04-02 23:01:38 +08:00
|
|
|
|
ID2D1TransformedGeometry * pCollider;
|
2018-03-14 15:33:58 +08:00
|
|
|
|
D2D1_GEOMETRY_RELATION relation;
|
|
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Сλ<D0A1>ô<EFBFBD><C3B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
Renderer::getID2D1Factory()->CreateRectangleGeometry(
|
2018-05-09 00:34:15 +08:00
|
|
|
|
D2D1::RectF(0, 0, _width, _height),
|
2018-03-14 15:33:58 +08:00
|
|
|
|
&pRect1
|
|
|
|
|
|
);
|
|
|
|
|
|
// <20><><EFBFBD>ݶ<EFBFBD>ά<EFBFBD><CEAC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD><D7AA>
|
|
|
|
|
|
Renderer::getID2D1Factory()->CreateTransformedGeometry(
|
|
|
|
|
|
pRect1,
|
2018-05-09 00:34:15 +08:00
|
|
|
|
_finalMatri,
|
2018-04-02 23:01:38 +08:00
|
|
|
|
&pCollider
|
2018-03-14 15:33:58 +08:00
|
|
|
|
);
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȽϽڵ<CFBD><DAB5>Ĵ<EFBFBD>Сλ<D0A1>ô<EFBFBD><C3B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
Renderer::getID2D1Factory()->CreateRectangleGeometry(
|
2018-05-09 00:34:15 +08:00
|
|
|
|
D2D1::RectF(0, 0, node->_width, node->_height),
|
2018-03-14 15:33:58 +08:00
|
|
|
|
&pRect2
|
|
|
|
|
|
);
|
|
|
|
|
|
// <20><>ȡ<EFBFBD>ཻ״̬
|
2018-04-02 23:01:38 +08:00
|
|
|
|
pCollider->CompareWithGeometry(
|
2018-03-14 15:33:58 +08:00
|
|
|
|
pRect2,
|
2018-05-09 00:34:15 +08:00
|
|
|
|
node->_finalMatri,
|
2018-03-14 15:33:58 +08:00
|
|
|
|
&relation
|
|
|
|
|
|
);
|
2018-04-02 23:01:38 +08:00
|
|
|
|
// ɾ<><C9BE><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ײ<EFBFBD><D7B2>
|
2018-05-10 20:23:32 +08:00
|
|
|
|
SafeReleaseInterface(pRect1);
|
|
|
|
|
|
SafeReleaseInterface(pRect2);
|
|
|
|
|
|
SafeReleaseInterface(pCollider);
|
2018-04-01 23:08:11 +08:00
|
|
|
|
if ((relation != D2D1_GEOMETRY_RELATION_UNKNOWN) &&
|
|
|
|
|
|
(relation != D2D1_GEOMETRY_RELATION_DISJOINT))
|
2018-03-14 15:33:58 +08:00
|
|
|
|
{
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-03-06 09:56:17 +08:00
|
|
|
|
|
2018-03-11 23:56:40 +08:00
|
|
|
|
return false;
|
2018-03-06 09:56:17 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-07 16:37:12 +08:00
|
|
|
|
void e2d::Node::setAutoUpdate(bool bAutoUpdate)
|
2018-02-03 22:04:43 +08:00
|
|
|
|
{
|
2018-05-09 00:34:15 +08:00
|
|
|
|
_autoUpdate = bAutoUpdate;
|
2018-02-03 22:04:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-27 21:07:43 +08:00
|
|
|
|
void e2d::Node::setDefaultPiovt(double defaultPiovtX, double defaultPiovtY)
|
2017-11-09 18:22:41 +08:00
|
|
|
|
{
|
2018-05-09 00:34:15 +08:00
|
|
|
|
s_fDefaultPiovtX = min(max(float(defaultPiovtX), 0), 1);
|
|
|
|
|
|
s_fDefaultPiovtY = min(max(float(defaultPiovtY), 0), 1);
|
2017-11-09 18:22:41 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-05-07 15:48:06 +08:00
|
|
|
|
void e2d::Node::setDefaultColliderEnable(bool enable)
|
2018-03-07 20:14:58 +08:00
|
|
|
|
{
|
2018-05-07 15:48:06 +08:00
|
|
|
|
s_fDefaultColliderEnabled = enable;
|
2018-03-07 20:14:58 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-05-08 20:03:29 +08:00
|
|
|
|
void e2d::Node::onDestroy()
|
2018-04-21 18:22:01 +08:00
|
|
|
|
{
|
|
|
|
|
|
ActionManager::__clearAllBindedWith(this);
|
2018-05-09 00:34:15 +08:00
|
|
|
|
ColliderManager::__removeCollider(_collider);
|
|
|
|
|
|
for (auto child : _children)
|
2018-04-21 18:22:01 +08:00
|
|
|
|
{
|
2018-05-19 01:10:37 +08:00
|
|
|
|
GC::release(child);
|
2018-04-21 18:22:01 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-07 16:37:12 +08:00
|
|
|
|
void e2d::Node::resumeAllActions()
|
2017-10-21 19:09:31 +08:00
|
|
|
|
{
|
2018-03-11 23:56:40 +08:00
|
|
|
|
ActionManager::__resumeAllBindedWith(this);
|
2017-10-21 19:09:31 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-07 16:37:12 +08:00
|
|
|
|
void e2d::Node::pauseAllActions()
|
2017-10-21 19:09:31 +08:00
|
|
|
|
{
|
2018-03-11 23:56:40 +08:00
|
|
|
|
ActionManager::__pauseAllBindedWith(this);
|
2017-10-21 19:09:31 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-07 16:37:12 +08:00
|
|
|
|
void e2d::Node::stopAllActions()
|
2017-10-21 19:09:31 +08:00
|
|
|
|
{
|
2018-03-11 23:56:40 +08:00
|
|
|
|
ActionManager::__stopAllBindedWith(this);
|
2017-10-21 19:09:31 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-07 16:37:12 +08:00
|
|
|
|
void e2d::Node::setVisiable(bool value)
|
2017-10-12 23:34:13 +08:00
|
|
|
|
{
|
2018-05-09 00:34:15 +08:00
|
|
|
|
_visiable = value;
|
2017-10-12 23:34:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-05-07 15:48:06 +08:00
|
|
|
|
void e2d::Node::setName(const String& name)
|
2017-10-14 11:40:47 +08:00
|
|
|
|
{
|
2018-02-07 16:37:12 +08:00
|
|
|
|
WARN_IF(name.isEmpty(), "Invalid Node name.");
|
2017-10-14 11:40:47 +08:00
|
|
|
|
|
2018-05-08 20:03:29 +08:00
|
|
|
|
if (!name.isEmpty() && _name != name)
|
2017-10-14 11:40:47 +08:00
|
|
|
|
{
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD><DAB5><EFBFBD>
|
2018-05-08 20:03:29 +08:00
|
|
|
|
_name = name;
|
2017-10-14 11:40:47 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD> Hash <20><>
|
2018-05-09 00:34:15 +08:00
|
|
|
|
_hashName = name.getHashCode();
|
2017-10-14 11:40:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-10-17 21:22:25 +08:00
|
|
|
|
|
2018-02-07 16:37:12 +08:00
|
|
|
|
void e2d::Node::_setParentScene(Scene * scene)
|
2017-10-17 21:22:25 +08:00
|
|
|
|
{
|
2018-05-09 00:34:15 +08:00
|
|
|
|
_parentScene = scene;
|
|
|
|
|
|
for (auto child : _children)
|
2017-10-17 21:22:25 +08:00
|
|
|
|
{
|
2018-02-03 22:04:43 +08:00
|
|
|
|
child->_setParentScene(scene);
|
2017-10-17 21:22:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|