#pragma once #include #include "EngineCore/Asset_ImagePack.h" #include "EngineFrame/Component/Component.h" class Game; /** * @brief Sprite类,继承自Component类,用于表示游戏中的精灵组件 */ class Sprite : public Component { private: /* data */ SDL_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 清理组件资源 */ void Clear() override; /** * @brief 获取纹理 * @return SDL_Texture* 纹理指针 */ SDL_Texture *GetTexture(); public: // 组件标签 Tag m_tag = Tag::RENDER | Tag::UPDATE; // 标记该组件需要渲染和更新 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; // 翻转 public: // 设置坐标 void SetPos(SDL_Point pos); // 设置混合模式 void SetBlendMode(SDL_BlendMode blendMode); // 设置旋转角度 void SetAngle(float angle); //设置中心点 void SetAnchor(SDL_FPoint anchor); // 获取坐标 SDL_Point GetPos(); // 获取混合模式 SDL_BlendMode GetBlendMode(); // 获取旋转角度 float GetAngle(); // 获取中心点 SDL_FPoint GetAnchor(); };