加入 Node节点类 还未测试新框架
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
#include "Asset/AssetManager.h"
|
||||
#include "Asset/Asset_Script.h"
|
||||
#include "Tool/Math.h"
|
||||
#include "EngineFrame/Actor/Actor.h"
|
||||
#include "EngineFrame/Base/Actor.h"
|
||||
#include "EngineCore/Game.h"
|
||||
|
||||
Animation::Animation()
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#pragma once
|
||||
#include "EngineFrame/Actor/Actor.h"
|
||||
#include "EngineFrame/Base/Actor.h"
|
||||
#include "EngineFrame/Component/Sprite.h"
|
||||
#include "Asset/AnimationStruct.h"
|
||||
#include <functional>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#pragma once
|
||||
#include "EngineFrame/Actor/Actor.h"
|
||||
#include "EngineFrame/Base/Actor.h"
|
||||
#include "EngineFrame/Render/Texture.h"
|
||||
#include "EngineFrame/Component/Sprite.h"
|
||||
class Canvas : public Actor
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
#include "Component.h"
|
||||
#include "EngineFrame/Actor/Actor.h"
|
||||
|
||||
void Component::Init()
|
||||
{
|
||||
addTag(Tag::COMPONENT);
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
#pragma once
|
||||
#include "EngineFrame/Base/BaseNode.h"
|
||||
|
||||
#include <SDL.h>
|
||||
class Actor;
|
||||
class Component : public BaseNode
|
||||
{
|
||||
|
||||
public:
|
||||
void Init() override;
|
||||
};
|
||||
@@ -1,13 +1,6 @@
|
||||
#include "RenderBase.h"
|
||||
#include "EngineFrame/Actor/Actor.h"
|
||||
#include "EngineFrame/Base/Actor.h"
|
||||
|
||||
RenderBase::RenderBase()
|
||||
{
|
||||
}
|
||||
|
||||
RenderBase::~RenderBase()
|
||||
{
|
||||
}
|
||||
|
||||
void RenderBase::CalcRenderInfo()
|
||||
{
|
||||
@@ -16,39 +9,23 @@ void RenderBase::CalcRenderInfo()
|
||||
|
||||
void RenderBase::Init()
|
||||
{
|
||||
Component::Init();
|
||||
// 标记该组件需要渲染和更新
|
||||
addTag(Tag::RENDER);
|
||||
addTag(Tag::UPDATE);
|
||||
addTag(Tag::TRANSFORM);
|
||||
// 计算渲染信息
|
||||
CalcRenderInfo();
|
||||
}
|
||||
|
||||
void RenderBase::Update(float deltaTime)
|
||||
{
|
||||
if (!Visible)
|
||||
return;
|
||||
Component::Update(deltaTime);
|
||||
|
||||
}
|
||||
|
||||
void RenderBase::Render()
|
||||
{
|
||||
if (!Visible)
|
||||
return;
|
||||
Component::Render();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void RenderBase::SetIterationPos(Vec2 pos)
|
||||
{
|
||||
Component::SetIterationPos(pos);
|
||||
Actor::SetIterationPos(pos);
|
||||
CalcRenderInfo(); // 更新渲染信息
|
||||
}
|
||||
|
||||
void RenderBase::SetIterationScale(Vec2 scale)
|
||||
{
|
||||
Component::SetIterationScale(scale);
|
||||
Actor::SetIterationScale(scale);
|
||||
CalcRenderInfo(); // 更新渲染信息
|
||||
}
|
||||
|
||||
@@ -56,31 +33,31 @@ void RenderBase::SetIterationRotation(float angle)
|
||||
{
|
||||
if (!Visible)
|
||||
return;
|
||||
Component::SetIterationRotation(angle);
|
||||
Actor::SetIterationRotation(angle);
|
||||
CalcRenderInfo(); // 更新渲染信息
|
||||
}
|
||||
|
||||
void RenderBase::SetPos(Vec2 pos)
|
||||
{
|
||||
Component::SetPos(pos);
|
||||
Actor::SetPos(pos);
|
||||
|
||||
CalcRenderInfo(); // 更新渲染信息
|
||||
}
|
||||
|
||||
void RenderBase::SetScale(Vec2 scale)
|
||||
{
|
||||
Component::SetScale(scale);
|
||||
Actor::SetScale(scale);
|
||||
CalcRenderInfo(); // 更新渲染信息
|
||||
}
|
||||
|
||||
void RenderBase::SetRotation(float angle)
|
||||
{
|
||||
Component::SetRotation(angle);
|
||||
Actor::SetRotation(angle);
|
||||
CalcRenderInfo(); // 更新渲染信息
|
||||
}
|
||||
|
||||
void RenderBase::SetAnchor(Vec2 anchor)
|
||||
{
|
||||
Component::SetAnchor(anchor);
|
||||
Actor::SetAnchor(anchor);
|
||||
CalcRenderInfo(); // 更新渲染信息
|
||||
}
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
#pragma once
|
||||
#include "EngineFrame/Base/Actor.h"
|
||||
|
||||
#include "EngineFrame/Component/Component.h"
|
||||
|
||||
class RenderBase : public Component
|
||||
class RenderBase : public Actor
|
||||
{
|
||||
|
||||
public:
|
||||
@@ -19,21 +18,11 @@ public:
|
||||
bool Visible = true;
|
||||
// 是否在屏幕内
|
||||
bool IsInScreen = false;
|
||||
//渲染矩阵
|
||||
GlMatrix RenderMatrix;
|
||||
};
|
||||
|
||||
public:
|
||||
RenderBase(/* args */);
|
||||
~RenderBase();
|
||||
|
||||
public:
|
||||
void Init() override;
|
||||
|
||||
void Update(float deltaTime) override;
|
||||
void Render() override;
|
||||
|
||||
public:
|
||||
public:
|
||||
// 设置迭代的坐标
|
||||
void SetIterationPos(Vec2 pos) override;
|
||||
|
||||
@@ -43,35 +43,6 @@ RefPtr<Texture> Sprite::GetTexture()
|
||||
return m_texture;
|
||||
}
|
||||
|
||||
GlMatrix Sprite::matrix3x2ToGLMatrix(const Matrix3x2 &mat)
|
||||
{
|
||||
return {
|
||||
// 列0:x轴线性变换
|
||||
mat._11, // [0][0]
|
||||
mat._12, // [1][0]
|
||||
0.0f, // [2][0]
|
||||
0.0f, // [3][0]
|
||||
|
||||
// 列1:y轴线性变换
|
||||
mat._21, // [0][1]
|
||||
mat._22, // [1][1]
|
||||
0.0f, // [2][1]
|
||||
0.0f, // [3][1]
|
||||
|
||||
// 列2:z轴(固定)
|
||||
0.0f, // [0][2]
|
||||
0.0f, // [1][2]
|
||||
1.0f, // [2][2]
|
||||
0.0f, // [3][2]
|
||||
|
||||
// 列3:平移
|
||||
mat._31, // [0][3](x平移)
|
||||
mat._32, // [1][3](y平移)
|
||||
0.0f, // [2][3]
|
||||
1.0f // [3][3]
|
||||
};
|
||||
}
|
||||
|
||||
void Sprite::CalcRenderInfoLogic()
|
||||
{
|
||||
// 获取至在最终的父对象检查是否显示
|
||||
@@ -105,8 +76,8 @@ void Sprite::CalcRenderInfoLogic()
|
||||
// 纹理数据里带的偏移数据 有这个偏移才能保证动画播放时视觉中心点在一个点上
|
||||
auto T_Size = m_texture->getSize();
|
||||
auto T_Pos = m_texture->getPos();
|
||||
float texturePosX = flipX ? -(T_Size.width + T_Pos.x) + SDL_abs(transform.position.x * 2) : T_Pos.x;
|
||||
float texturePosY = flipY ? -(T_Size.height + T_Pos.y) + SDL_abs(transform.position.y * 2) : T_Pos.y;
|
||||
float texturePosX = flipX ? -((float)T_Size.width + (float)T_Pos.x) + SDL_fabsf(transform.position.x * 2.0f) : (float)T_Pos.x;
|
||||
float texturePosY = flipY ? -((float)T_Size.height + (float)T_Pos.y) + SDL_fabsf(transform.position.y * 2.0f) : (float)T_Pos.y;
|
||||
|
||||
// 先计算Img坐标与精灵坐标合成后的真实坐标
|
||||
float RealPosX = transform.position.x + texturePosX;
|
||||
@@ -117,22 +88,22 @@ void Sprite::CalcRenderInfoLogic()
|
||||
float baseY = transformIter.position.y + RealPosY;
|
||||
|
||||
// 获取当前帧的原始尺寸
|
||||
int frameWidth = Size.width;
|
||||
int frameHeight = Size.height;
|
||||
float frameWidth = (float)Size.width;
|
||||
float frameHeight = (float)Size.height;
|
||||
|
||||
// 原始锚点偏移(基于帧尺寸)
|
||||
float origAnchorOffsetX = int(frameWidth * Anchor.x);
|
||||
float origAnchorOffsetY = int(frameHeight * Anchor.y);
|
||||
float origAnchorOffsetX = frameWidth * Anchor.x;
|
||||
float origAnchorOffsetY = frameHeight * Anchor.y;
|
||||
|
||||
// 缩放的绝对值
|
||||
float absScaleX = SDL_fabs(scaleX);
|
||||
float absScaleY = SDL_fabs(scaleY);
|
||||
float absScaleX = SDL_fabsf(scaleX);
|
||||
float absScaleY = SDL_fabsf(scaleY);
|
||||
// 缩放后的尺寸
|
||||
float scaledWidth = frameWidth * absScaleX;
|
||||
float scaledHeight = frameHeight * absScaleY;
|
||||
// 缩放后的锚点偏移
|
||||
float scaledAnchorOffsetX = int(origAnchorOffsetX * absScaleX);
|
||||
float scaledAnchorOffsetY = int(origAnchorOffsetY * absScaleY);
|
||||
float scaledAnchorOffsetX = origAnchorOffsetX * absScaleX;
|
||||
float scaledAnchorOffsetY = origAnchorOffsetY * absScaleY;
|
||||
|
||||
// 计算缩放后的锚点偏移与原锚点偏移的差值
|
||||
float scaleOffsetX = scaledAnchorOffsetX - origAnchorOffsetX;
|
||||
@@ -142,9 +113,6 @@ void Sprite::CalcRenderInfoLogic()
|
||||
float Xpos = baseX - scaleOffsetX;
|
||||
float Ypos = baseY - scaleOffsetY;
|
||||
|
||||
Xpos = (int)Xpos; // 强制转换为整数
|
||||
Ypos = (int)Ypos; // 强制转换为整数
|
||||
|
||||
// 更新渲染信息
|
||||
_RenderGuidanceInfo.rect = {Xpos, Ypos, scaledWidth, scaledHeight};
|
||||
_RenderGuidanceInfo.AnchorPos = {scaledAnchorOffsetX, scaledAnchorOffsetY};
|
||||
@@ -152,8 +120,8 @@ void Sprite::CalcRenderInfoLogic()
|
||||
m_texture->setAlpha(this->Alpha);
|
||||
|
||||
// 屏幕内检测
|
||||
int screenWidth = Game::GetInstance().Screen_W;
|
||||
int screenHeight = Game::GetInstance().Screen_H;
|
||||
float screenWidth = (float)Game::GetInstance().Screen_W;
|
||||
float screenHeight = (float)Game::GetInstance().Screen_H;
|
||||
bool isInScreen = (Xpos + scaledWidth >= 0 && Xpos <= screenWidth && Ypos + scaledHeight >= 0 && Ypos <= screenHeight);
|
||||
_RenderGuidanceInfo.IsInScreen = isInScreen;
|
||||
|
||||
|
||||
@@ -33,10 +33,6 @@ public:
|
||||
std::string imgPath;
|
||||
int Index;
|
||||
|
||||
Matrix3x2 transform_matrix_;
|
||||
|
||||
GlMatrix matrix3x2ToGLMatrix(const Matrix3x2 &mat);
|
||||
|
||||
public:
|
||||
// 计算渲染信息
|
||||
void CalcRenderInfoLogic();
|
||||
|
||||
@@ -10,7 +10,7 @@ public:
|
||||
~Text();
|
||||
|
||||
// 显式引入基类的Init方法,避免隐藏
|
||||
using Component::Init;
|
||||
using Actor::Init;
|
||||
void Init(std::string Str, TTF_Font *font, SDL_Color color);
|
||||
void Render() override;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user