parent
6868d746da
commit
b4404db7b7
|
|
@ -62,10 +62,14 @@ namespace easy2d
|
||||||
if (pause_)
|
if (pause_)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
OnUpdate(dt);
|
|
||||||
UpdateActions(this, dt);
|
UpdateActions(this, dt);
|
||||||
UpdateTasks(dt);
|
UpdateTasks(dt);
|
||||||
|
|
||||||
|
if (cb_update_)
|
||||||
|
cb_update_(dt);
|
||||||
|
|
||||||
|
OnUpdate(dt);
|
||||||
|
|
||||||
if (!children_.IsEmpty())
|
if (!children_.IsEmpty())
|
||||||
{
|
{
|
||||||
NodePtr next;
|
NodePtr next;
|
||||||
|
|
@ -225,11 +229,7 @@ namespace easy2d
|
||||||
dirty_transform_ = false;
|
dirty_transform_ = false;
|
||||||
dirty_transform_inverse_ = true;
|
dirty_transform_inverse_ = true;
|
||||||
|
|
||||||
// matrix multiplication is optimized by expression template
|
transform_matrix_ = transform_.ToMatrix();
|
||||||
transform_matrix_ = Matrix::Scaling(transform_.scale)
|
|
||||||
* Matrix::Skewing(transform_.skew.x, transform_.skew.y)
|
|
||||||
* Matrix::Rotation(transform_.rotation)
|
|
||||||
* Matrix::Translation(transform_.position);
|
|
||||||
|
|
||||||
Point offset{ -size_.x * anchor_.x, -size_.y * anchor_.y };
|
Point offset{ -size_.x * anchor_.x, -size_.y * anchor_.y };
|
||||||
transform_matrix_.Translate(offset);
|
transform_matrix_.Translate(offset);
|
||||||
|
|
|
||||||
|
|
@ -45,6 +45,7 @@ namespace easy2d
|
||||||
friend class IntrusiveList<NodePtr>;
|
friend class IntrusiveList<NodePtr>;
|
||||||
|
|
||||||
using Children = IntrusiveList<NodePtr>;
|
using Children = IntrusiveList<NodePtr>;
|
||||||
|
using UpdateCallback = std::function<void(Duration)>;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Node();
|
Node();
|
||||||
|
|
@ -351,6 +352,12 @@ namespace easy2d
|
||||||
// 节点更新是否暂停
|
// 节点更新是否暂停
|
||||||
inline bool IsUpdatePausing() const { return pause_; }
|
inline bool IsUpdatePausing() const { return pause_; }
|
||||||
|
|
||||||
|
// 设置更新时的回调函数
|
||||||
|
inline void SetCallbackOnUpdate(UpdateCallback const& cb) { cb_update_ = cb; }
|
||||||
|
|
||||||
|
// 获取更新时的回调函数
|
||||||
|
inline UpdateCallback const& GetCallbackOnUpdate() { return cb_update_; }
|
||||||
|
|
||||||
// 设置默认锚点
|
// 设置默认锚点
|
||||||
static void SetDefaultAnchor(
|
static void SetDefaultAnchor(
|
||||||
float anchor_x,
|
float anchor_x,
|
||||||
|
|
@ -384,6 +391,7 @@ namespace easy2d
|
||||||
Node* parent_;
|
Node* parent_;
|
||||||
Scene* scene_;
|
Scene* scene_;
|
||||||
Children children_;
|
Children children_;
|
||||||
|
UpdateCallback cb_update_;
|
||||||
|
|
||||||
mutable bool dirty_transform_;
|
mutable bool dirty_transform_;
|
||||||
mutable bool dirty_transform_inverse_;
|
mutable bool dirty_transform_inverse_;
|
||||||
|
|
|
||||||
|
|
@ -46,5 +46,14 @@ namespace easy2d
|
||||||
skew == other.skew &&
|
skew == other.skew &&
|
||||||
rotation == other.rotation;
|
rotation == other.rotation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline math::Matrix ToMatrix() const
|
||||||
|
{
|
||||||
|
// matrix multiplication is optimized by expression template
|
||||||
|
return Matrix::Scaling(scale)
|
||||||
|
* Matrix::Skewing(skew.x, skew.y)
|
||||||
|
* Matrix::Rotation(rotation)
|
||||||
|
* Matrix::Translation(position);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue