105 lines
2.5 KiB
C++
105 lines
2.5 KiB
C++
#pragma once
|
||
#include <string>
|
||
#include "EngineCore/Asset_ImagePack.h"
|
||
#include "EngineFrame/Component/Component.h"
|
||
|
||
class Game;
|
||
/**
|
||
* @brief Sprite类,继承自Component类,用于表示游戏中的精灵组件
|
||
*/
|
||
class Sprite : public Component
|
||
{
|
||
private:
|
||
/* data */
|
||
RefPtr<Texture> m_texture = nullptr;
|
||
|
||
public:
|
||
/**
|
||
* @brief Sprite类的默认构造函数
|
||
*/
|
||
Sprite(/* args */);
|
||
/**
|
||
* @brief Sprite类的带参数构造函数
|
||
* @param imgPath 纹理图片路径
|
||
* @param Index 索引值
|
||
*/
|
||
Sprite(std::string imgPath, int Index);
|
||
/**
|
||
* @brief Sprite类的析构函数
|
||
*/
|
||
~Sprite();
|
||
|
||
// 显式引入基类的Init方法,避免隐藏
|
||
using Component::Init;
|
||
/**
|
||
* @brief 初始化Sprite组件
|
||
* @param imgPath 纹理图片路径
|
||
* @param Index 索引值
|
||
*/
|
||
void Init(std::string imgPath, int Index);
|
||
/**
|
||
* @brief 处理事件
|
||
* @param e SDL事件指针
|
||
*/
|
||
void HandleEvents(SDL_Event *e) override;
|
||
/**
|
||
* @brief 更新组件状态
|
||
* @param deltaTime 时间增量
|
||
*/
|
||
void Update(float deltaTime) override;
|
||
/**
|
||
* @brief 渲染组件
|
||
* @param deltaTime 时间增量
|
||
*/
|
||
void Render(float deltaTime) override;
|
||
/**
|
||
* @brief 渲染组件
|
||
* @param deltaTime 时间增量
|
||
*/
|
||
void RenderByAni(float deltaTime, SDL_Point pos);
|
||
/**
|
||
* @brief 清理组件资源
|
||
*/
|
||
void Clear() override;
|
||
|
||
/**
|
||
* @brief 获取纹理
|
||
* @return SDL_Texture* 纹理指针
|
||
*/
|
||
RefPtr<Texture> GetTexture();
|
||
|
||
public:
|
||
SDL_Point Pos = {0, 0}; // 位置坐标
|
||
SDL_Point TextureSize = {0, 0}; // 纹理大小
|
||
SDL_Point Size = {0, 0}; // 大小
|
||
SDL_Point Anchor = {0, 0}; // 中心点
|
||
float Angle = 0.0f; // 旋转角度
|
||
SDL_RendererFlip flip = SDL_FLIP_NONE; // 翻转
|
||
|
||
// 是否在需要渲染的屏幕上
|
||
bool isRenderScreen = true;
|
||
|
||
public:
|
||
// 设置坐标
|
||
void SetPos(SDL_Point pos);
|
||
// 设置混合模式
|
||
void SetBlendMode(SDL_BlendMode blendMode);
|
||
// 设置旋转角度
|
||
void SetAngle(float angle);
|
||
// 设置中心点
|
||
void SetAnchor(SDL_FPoint anchor);
|
||
// 设置大小
|
||
void SetSize(SDL_Point size);
|
||
|
||
// 获取坐标
|
||
SDL_Point GetPos();
|
||
// 获取混合模式
|
||
SDL_BlendMode GetBlendMode();
|
||
// 获取旋转角度
|
||
float GetAngle();
|
||
// 获取中心点
|
||
SDL_FPoint GetAnchor();
|
||
// 获取大小
|
||
SDL_Point GetSize();
|
||
};
|