SwitchGame/source/EngineFrame/Component/Sprite.h

104 lines
2.5 KiB
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#pragma once
#include <string>
#include "EngineCore/Asset_ImagePack.h"
#include "EngineFrame/Component/Component.h"
#include "EngineFrame/Render/Texture.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类的带参数构造函数
* @param imgPath 纹理图片文件路径
*/
Sprite(std::string PngPath);
/**
* @brief Sprite类的析构函数
*/
~Sprite();
// 显式引入基类的Init方法避免隐藏
using Component::Init;
/**
* @brief 初始化Sprite组件
*/
void Init();
/**
* @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* 纹理指针
*/
RefPtr<Texture> GetTexture();
public:
VecPos Pos = {0, 0}; // 位置坐标
VecSize TextureSize = {0, 0}; // 纹理大小
VecSize Size = {0, 0}; // 大小
VecPos Anchor = {0, 0}; // 中心点
float Angle = 0.0f; // 旋转角度
SDL_RendererFlip flip = SDL_FLIP_NONE; // 翻转
// 是否在需要渲染的屏幕上
bool isRenderScreen = true;
public:
// 设置坐标
void SetPos(VecPos pos);
// 设置混合模式
void SetBlendMode(SDL_BlendMode blendMode);
// 设置旋转角度
void SetAngle(float angle);
// 设置中心点
void SetAnchor(VecFPos anchor);
// 设置大小
void SetSize(VecSize size);
// 获取坐标
VecPos GetPos();
// 获取混合模式
SDL_BlendMode GetBlendMode();
// 获取旋转角度
float GetAngle();
// 获取中心点
VecFPos GetAnchor();
// 获取大小
VecSize GetSize();
};