我的脚本无法运行,因为它会打开一个窗口并关闭它。它在加载文件时失败。该脚本适用于我的笔记本电脑,但不适用于我的台式电脑,并且所有的neccecary文件都在那里。这是关于这个功能的;在SDL中使用自定义函数加载图像失败
这是我的功能load_image()
;
SDL_Surface *load_image(std::string filename)
{
//The image that's loaded
SDL_Surface* loadedImage = NULL;
//The optimized surface that will be used
SDL_Surface* optimizedImage = NULL;
//Load the image
loadedImage = IMG_Load(filename.c_str());
//If the image loaded
if(loadedImage != NULL)
{
//Create an optimized surface
optimizedImage = SDL_DisplayFormatAlpha(loadedImage);
//Free the old surface
SDL_FreeSurface(loadedImage);
//If the surface was optimized
if(optimizedImage != NULL)
{
//Color key surface
SDL_SetColorKey(optimizedImage, SDL_SRCCOLORKEY, SDL_MapRGB(optimizedImage->format, 0, 0xFF, 0xFF));
}
}
//Return the optimized surface
return optimizedImage;
}
我这样称呼它;
sprite = load_image("sprites.png");
if(sprite == NULL)
{
return false;
}
唯一的问题是,它始终返回false,即使该文件是在那里。问题是,这个代码不会在我的笔记本电脑上返回false!
两台计算机上的文件是否位于相同路径中? – 2012-03-09 22:33:47
不,但我在两台机器上完全重新编译它,所以它应该没有关系? – 2012-03-09 22:39:19