e 是什么
SDL_Event e;
如何将 e 从一个函数传递到另一个函数,然后再传递到另一个函数。 这可能吗?
基本上是 e bool 或 int
bool x_out_window()
{
bool quit = false;
SDL_Event e;
while( !quit )
{
while( SDL_PollEvent( &e ) != 0 )
{
if( e.type == SDL_QUIT )
quit = true;
else
detect_key_press(e.type);
}
}
}
bool detect_key_press(e.type)
{
//SDL_Event e;
if( e.type == SDL_KEYDOWN )
{
//Select surfaces based on key press
switch( e.key.keysym.sym )
{
case SDLK_UP:
gCurrentSurface = gKeyPressSurfaces[ KEY_PRESS_SURFACE_UP ];
break;
case SDLK_DOWN:
gCurrentSurface = gKeyPressSurfaces[ KEY_PRESS_SURFACE_DOWN ];
break;
case SDLK_LEFT:
gCurrentSurface = gKeyPressSurfaces[ KEY_PRESS_SURFACE_LEFT ];
break;
case SDLK_RIGHT:
gCurrentSurface = gKeyPressSurfaces[ KEY_PRESS_SURFACE_RIGHT ];
break;
default:
gCurrentSurface = gKeyPressSurfaces[ KEY_PRESS_SURFACE_DEFAULT ];
break;
}
SDL_BlitSurface( gXOut, NULL, gScreenSurface, NULL );
SDL_UpdateWindowSurface( gWindow );
}
}
如果这是一个愚蠢的问题,我很抱歉,但我无法理解这个概念,我是编码新手。
最佳答案
只需将函数 2 声明为
void funtion2(SDL_Event e){
//...
}
在 C++ 中,您需要为函数(这里可能是 void
)和所有参数(名为 e
的 SDL_Event
在这里)
关于c++ - SDL_事件e;传递给函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35231461/