0

我正在 Xcode 4.6 中尝试一个 SDL 项目。我按照HERE的说明进行操作,一切顺利。我什至在那里运行了测试代码。

现在当我尝试加载 BMP

SDL_Surface* bmp = SDL_LoadBMP("cb.bmp");

它说无法加载bmp。但如果我使用Absoulte path,它工作正常。

问题是什么?我应该怎么做才能使用相对路径?

文件夹结构如下:

sdl_test
    sdl_test.xcodeproj
    sdl_test
        cb.bmp
        SDLMain.m
        SDLMain.h
        main.cpp
        sdl_test.1
4

1 回答 1

0

当我开始使用 Xcode 时,我遇到了同样的问题。

您必须更改 SDLMain.m 文件中的工作目录。找到 setupWorkingDirectory 方法,并将其替换为:

/* Set the working directory to the .app's parent directory */
- (void) setupWorkingDirectory:(BOOL)shouldChdir
{ 
    //setting the working directoy to MyApp.app/Contents/Resources/  
    NSString *resourcePath = [[NSBundle mainBundle] resourcePath];
    [[NSFileManager defaultManager] changeCurrentDirectoryPath:resourcePath];

}

希望这有效。

于 2013-05-20T18:04:59.737 回答