ios - SDL 和 iOS main() 方法冲突
<p><p>我了解到 SDL 项目需要 main() 方法来运行循环,代码如下:</p>
<pre><code>#include "SDL.h"
int main(int argc, char *argv[])
{
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
printf("%s\n", SDL_GetError());
}
SDL_Window *window = SDL_CreateWindow(NULL, 0, 0, 320, 640, SDL_WINDOW_OPENGL | SDL_WINDOW_FULLSCREEN);
SDL_Renderer *renderer = SDL_CreateRenderer(window, 0, 0);
SDL_Surface *bmp_surface = SDL_LoadBMP("space.bmp");
SDL_Texture *space = SDL_CreateTextureFromSurface(renderer, bmp_surface);
SDL_FreeSurface(bmp_surface);
SDL_RenderCopy(renderer, space, NULL, NULL);
SDL_RenderPresent(renderer);
int done = 0;
while (!done) {
Uint32 startFrame = SDL_GetTicks();
SDL_Event event;
while (SDL_PollEvent(&event)) {
if (event.type == SDL_QUIT) {
done = 1;
}
}
Uint32 endFrame = SDL_GetTicks();
Sint32 delay = MILLESECONDS_PER_FRAME - (endFrame - startFrame);
if (delay < 0) {
delay = 0;
} else if (delay > MILLESECONDS_PER_FRAME) {
delay = MILLESECONDS_PER_FRAME;
}
SDL_Delay(delay);
}
SDL_DestroyTexture(space);
SDL_Quit();
return 0;
}
</code></pre>
<p>而iOS项目也需要main()方法,代码如下:</p>
<pre><code>#import <UIKit/UIKit.h>
#import "AppDelegate.h"
int main(int argc, char * argv[])
{
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass());
}
}
</code></pre>
<p>现在我需要将 SDL 库集成到 iOS 项目中,但需要两个 main() 方法。如何?如果是,有人可以显示更多代码吗?谢谢。</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>你需要获取 SDLMain.m 和 SDLMain.h</p>
<p>在此处了解更多信息 - <a href="http://beefchunk.com/documentation/lib/libSDL/faq/FAQ-MacOSX.html" rel="noreferrer noopener nofollow">http://beefchunk.com/documentation/lib/libSDL/faq/FAQ-MacOSX.html</a> </p></p>
<p style="font-size: 20px;">关于ios - SDL 和 iOS main() 方法冲突,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/23452160/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/23452160/
</a>
</p>
页:
[1]