我了解到SDL项目需要main()方法来运行循环,代码如下:
#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;
}
iOS项目也需要main()方法,代码如下:
#import <UIKit/UIKit.h>
#import "AppDelegate.h"
int main(int argc, char * argv[])
{
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
}
现在,我需要将SDL库集成到iOS项目中,但是需要两个main()方法。怎么样?如果是,有人还能显示更多代码吗?谢谢。
最佳答案
您需要获取SDLMain.m和SDLMain.h
在此处详细了解-http://beefchunk.com/documentation/lib/libSDL/faq/FAQ-MacOSX.html