这是我初始化 SDL 的方式:
//initialize engine and set main loop callback... kind of awkward is there a better way to do this?
extern "C"{
CBCore::Engine *engine;
void UpdateLoop(void *f)
{
engine->updateLoop();
}
int main(int argc, char *argv[])
{
engine = new CBCore::Engine();
engine->init();
Assert(engine->window(), "Window not set for iOS animation callback");
SDL_iPhoneSetAnimationCallback(engine->window(), 1, UpdateLoop, NULL);
return 0;
}
}
//init function of engine, initializes required SDL subsystems and creates window
void Engine::init()
{
SDL_Log("Initializing engine!");
/* initialize SDL */
if(SDL_Init(0) != 0){
Assert(0, "Could not initialize SDL");
}
if (SDL_InitSubSystem(SDL_INIT_VIDEO) != 0) {
Assert(0, "Could not initialize SDL Video");
}
if(SDL_InitSubSystem(SDL_INIT_TIMER) != 0){
Assert(0, "Could not initialize SDL Timer");
}
_window = SDL_CreateWindow(NULL, 0, 0, 480, 320, SDL_WINDOW_SHOWN | SDL_WINDOW_FULLSCREEN | SDL_WINDOW_BORDERLESS | SDL_WINDOW_OPENGL);
Assert(_window, "Could not create window");
_context = SDL_GL_CreateContext(pimpl->window);
Assert(_context, "Could not create context");
SDL_Log("Engine successfully initialized!");
}
//loop
void Engine::updateLoop()
{
SDL_Event event;
SDL_Log("Polling events");
while(SDL_PollEvent(&event)) {
SDL_Log("Polled event %d", event.type);
}
}
循环被调用,我在启动时收到 4 个事件:SDL_APP_DIDENTERFOREGROUND、SDL_WINDOWEVENT_SIZE_CHANGED、SDL_WINDOWEVENT_SHOWN 和 SDL_WINDOWEVENT_ENTER;我还收到了输入背景消息等。但是我可以点击/触摸模拟器/设备,直到奶牛回家但没有收到任何事件......我错过了什么吗?