SDL_image로 사전을 만든 것처럼 SDL_ttf로 글꼴 사전을 만들려고합니다. 모두 사전 얹는하나의 함수에서 Make_Pair 식별자를 찾을 수 없지만 다른 함수에서 찾을 수 있습니다.
struct fontinfo
{
string assetname;
int size;
};
: 글꼴이 pnt_size
에 저장되어 있기 때문에 나는이 정보를 포함하는 구조체를 만들어
map<string, SDL_Surface*> imageDictionary;
map<fontinfo*, TTF_Font*> fontDictionary;
둘 사이의 차이는 글꼴 사전뿐만 아니라를 포함 할 필요가 있다는 것입니다 문자열을 파일뿐만 아니라 글꼴의 크기에도 적용합니다.
그런 다음 이미지 또는 글꼴이 객체에 의해 요청을 받으면 객체에 대해 get
함수를 호출합니다. 이제 getSprite
잘 작동 :
TTF_Font* ResourceManager::getFont(string assetname, int size)
{
if (assetname == "" || size < 0)
return NULL;
fontinfo* info = new fontinfo();
info->assetname = assetname;
info->size = size;
map<fontinfo*, TTF_Font*>::iterator it = fontDictionary.find(info);
if (it != fontDictionary.end())
return it->second;
else
{
TTF_Font* font = Load_Font(assetname, size);
if (font != NULL)
fontDictionary.insert(make_pair(info, font));
return font;
}
}
컴파일러는 나에게 및 발견하지 ID를 알려줍니다
SDL_Surface* ResourceManager::getSprite(string assetname)
{
if (assetname == "")
return NULL;
map<string, SDL_Surface*>::iterator it = imageDictionary.find(assetname);
if (it != imageDictionary.end())
return it->second;
else
{
SDL_Surface* image = Load_Image(assetname);
if (image != NULL)
imageDictionary.insert(make_pair(assetname, image));
return image;
}
}
getFont
방법은 그것이 fontinfo
대신 string
(A)의 사용한다는 사실을 제외하고 거의 동일 make_pair
은이며, make_pair
기능의 경우에만 getFont
입니다. make_pair
getSprite
에 문제가 없습니다.
안녕하세요,이 파일들은 같은 파일에 있습니까? 그것은 하나의 파일처럼 보일 뿐이며'#include'과 다른 파일은 포함되어 있습니다 (또는 포함하고있는 다른 것을 포함합니다). –
David
그들은 실제로 같은 파일에 있습니다. 둘 다 Class ResourceManager에서 가져온 것이고 그들은 서로 바로 위에 있습니다. – M4st3rM1nd