14_C++精灵库之shape.h头文件源代码(2026年1月15日版)

#ifndef SHAPE_H
#define SHAPE_H

#include <SDL2/SDL.h>
#include <string>
extern bool m_loadingTexture;  //是否正在加载纹理 

class Shape {
private:      
    std::string m_imgpath;     //造型的图片路径 (反斜杠要变成正斜杠存储) 
    int width;              // 造型宽度
    int height;             // 造型高度    
    SDL_Texture* raw_texture; // 造型的原始纹理
    SDL_Surface* raw_surface; //造型的原始表面 

public:   
    // 1. 添加默认构造函数
    Shape()  ;
    
    // 2. 带图片路径的构造函数
    Shape(std::string imgpath);
	    
    // 2. 带surface的构造函数
    Shape(SDL_Surface *sur);
    
    // 3. 拷贝构造函数
    Shape(const Shape *other);
    
    // 4. 析构函数
    ~Shape();
    
    // 加载纹理(需要渲染器)
    bool loadTexture(SDL_Renderer* renderer);
    
    // 获取纹理
    SDL_Texture* getTexture() const;
    // 获取表面 
    SDL_Surface* getSurface() const;
    
    std::string imgpath() const;  //获取造型的图片路径 
    // 获取宽度
    int getWidth() const;
    
    // 获取高度
    int getHeight() const;    
   
};

#endif // SHAPE_H

关于李兴球

李兴球的博客是Python创意编程原创博客
此条目发表在C++分类目录。将固定链接加入收藏夹。

发表回复