SwitchGame/source/EngineFrame/Component/Sprite.h

96 lines
2.4 KiB
C
Raw Normal View History

2025-09-15 11:28:54 +08:00
#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 */
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();
};