增加Node::setPosFixed方法,使节点坐标固定

This commit is contained in:
Nomango 2018-05-07 17:15:57 +08:00
parent fe9d155779
commit 718b1b1a1a
2 changed files with 17 additions and 1 deletions

View File

@ -35,6 +35,7 @@ e2d::Node::Node()
, m_bSortChildrenNeeded(false)
, m_bTransformNeeded(false)
, m_bAutoUpdate(true)
, m_bPositionFixed(false)
{
if (s_fDefaultColliderEnabled)
{
@ -224,7 +225,7 @@ void e2d::Node::_updateSelfTransform()
// 根据自身中心点变换 Final 矩阵
m_MatriFinal = m_MatriInitial * D2D1::Matrix3x2F::Translation(-pivot.x, -pivot.y);
// 和父节点矩阵相乘
if (m_pParent)
if (!m_bPositionFixed && m_pParent)
{
m_MatriInitial = m_MatriInitial * m_pParent->m_MatriInitial;
m_MatriFinal = m_MatriFinal * m_pParent->m_MatriInitial;
@ -420,6 +421,15 @@ void e2d::Node::setPos(double x, double y)
m_bTransformNeeded = true;
}
void e2d::Node::setPosFixed(bool fixed)
{
if (m_bPositionFixed == fixed)
return;
m_bPositionFixed = fixed;
m_bTransformNeeded = true;
}
void e2d::Node::movePosX(double x)
{
this->movePos(x, 0);

View File

@ -196,6 +196,11 @@ public:
double y
);
// 节点坐标固定
virtual void setPosFixed(
bool fixed
);
// 移动节点
virtual void movePosX(
double x
@ -470,6 +475,7 @@ protected:
bool m_bDisplayedInScene;
bool m_bSortChildrenNeeded;
bool m_bTransformNeeded;
bool m_bPositionFixed;
Collider * m_pCollider;
Scene * m_pParentScene;
Node * m_pParent;