64,691
社区成员
发帖
与我相关
我的任务
分享
#include<iostream>
#include<string>
#include<SDL.h>
#include<SDL_image.h>
#include<map>
using namespace std;
#ifndef THISISOURMANAGER
#define THISISOURMANAGER
class TextureManager
{
public:
bool load(string fileName, string id, SDL_Renderer* pRenderer);
void drawFrame(string id, int x, int y, int w, int h, int currentFrame,
int currentRow, SDL_Renderer* pRenderer, SDL_RendererFlip flip = SDL_FLIP_NONE);
void draw(string id, int x, int y, int w, int h, SDL_Renderer* pRenderer, SDL_RendererFlip flip = SDL_FLIP_NONE);
static TextureManager* Instance();
private:
map<string, SDL_Texture*> m_textureMap;
TextureManager(){}
static TextureManager* s_pInstance;
};
#endif
TextureManager* TextureManager::Instance()
{
if(s_pInstance == 0)
{
s_pInstance = new TextureManager();
return s_pInstance;
}
return s_pInstance;
}
if(!TextureManager::Instance()->load("assets/animate.png","animate",m_pRenderer))
{
return false;
}
TextureManager::Instance()->draw("animate",0,0,128,82,m_pRenderer);