73 lines
2.0 KiB
C++
73 lines
2.0 KiB
C++
#include "AnimationManager.h"
|
||
#include "EngineCore/Game.h"
|
||
|
||
AnimationManager::AnimationManager()
|
||
{
|
||
}
|
||
|
||
void AnimationManager::PreRender()
|
||
{
|
||
Actor::PreRender();
|
||
// 标记是否是第一个子对象(用于初始化min/max值)
|
||
bool isFirst = true;
|
||
float minX = 0.0f, minY = 0.0f; // 所有子对象的最小X、Y坐标
|
||
float maxX = 0.0f, maxY = 0.0f; // 所有子对象的最大X、Y坐标(右下角)
|
||
|
||
RefPtr<BaseNode> child = m_BaseNodes.GetFirst();
|
||
while (child)
|
||
{
|
||
// 转换为Animation对象
|
||
Animation *ani = static_cast<Animation *>(child.Get());
|
||
|
||
float width = ani->CurrentFrame->_RenderGuidanceInfo.rect.w;
|
||
float height = ani->CurrentFrame->_RenderGuidanceInfo.rect.h;
|
||
float x = ani->CurrentFrame->_RenderGuidanceInfo.rect.x;
|
||
float y = ani->CurrentFrame->_RenderGuidanceInfo.rect.y;
|
||
|
||
// 计算子对象的右下角坐标(左上角 + 宽高)
|
||
float currentMaxX = x + width;
|
||
float currentMaxY = y + height;
|
||
// 初始化或更新min/max值
|
||
if (isFirst)
|
||
{
|
||
minX = x;
|
||
minY = y;
|
||
maxX = currentMaxX;
|
||
maxY = currentMaxY;
|
||
isFirst = false;
|
||
}
|
||
else
|
||
{
|
||
minX = std::min(minX, x);
|
||
minY = std::min(minY, y);
|
||
maxX = std::max(maxX, currentMaxX);
|
||
maxY = std::max(maxY, currentMaxY);
|
||
}
|
||
|
||
child = child->GetNext();
|
||
}
|
||
// 计算最终的包围盒矩形
|
||
if (!isFirst) // 至少有一个子对象时才计算
|
||
{
|
||
m_RenderRect.x = minX; // 矩形左上角X
|
||
m_RenderRect.y = minY; // 矩形左上角Y
|
||
m_RenderRect.w = maxX - minX; // 矩形宽度(右下角X - 左上角X)
|
||
m_RenderRect.h = maxY - minY; // 矩形高度(右下角Y - 左上角Y)
|
||
}
|
||
}
|
||
|
||
void AnimationManager::Render()
|
||
{
|
||
Actor::Render();
|
||
}
|
||
|
||
void AnimationManager::AddAnimation(RefPtr<Animation> ani)
|
||
{
|
||
this->AddChild(ani);
|
||
}
|
||
|
||
void AnimationManager::Clear()
|
||
{
|
||
this->RemoveAllChild();
|
||
}
|