Hey Guys,
Im a beginner in C++ and SDL and im writing a game.
Im quite done, but my problem are the Keyboard Events, when i press a key, it sometimes gets not even noticed, sometimes i have to hold it down to get it noticed as a keypress and stuff like that,
so my game isn`t working that good. I don’t know whats wrong, so i would be very happy if you guys could help me out;
The “couts” “0 was pressed” and “w was pressed” are not for the game, i just put them in there to see whats wrong, why it won’t shoot and so on^^.
Here is the Code of the Function that “recognizes events”:
void CGame::ProcessEvents()
{
SDL_Event Event;
if (SDL_PollEvent(&Event))
{
if (Event.type == SDL_QUIT)
m_bGameIsRunning = false;
if (Event.type == SDL_KEYDOWN)
{
switch (Event.key.keysym.sym)
{
case(SDLK_SPACE) :
cout << “0 was pressed” << endl;
break;
case(SDLK_w) :
cout << “w was pressed” << endl;
}
}
}
}
The SDL_PumpEvents() Function is located in g_pFramework-Update() (I think it’s needed, pls tell me if its unnecessary^^)
The SDL_QUIT part works pretty smooth, i press the “X” and the window gets closed.
As I said, I am pretty new to SDL please tell me if something could get done better in an other way.
Here is The function where its used in even if i think the problem is in the function:
void CGame::Run()
{
while (m_bGameIsRunning == true)
{
ProcessEvents();
g_pFramework->Update();
g_pFramework->Clear();
m_pSpriteBackground->Render();
m_pPlayer->Update();
m_pPlayer->Render();
SpawnAsteroids();
CheckCollisions();
RenderAsteroids();
g_pFramework->UpdateWindow();
}
}
And here is the main- function, but I think the problem is in the function ProcessEvents:
int main(int argc, char *args[])
{
if (g_pFramework->Init(1520, 180) == false)
return 0;
CGame Game;
Game.Init();
Game.Run();
Game.Quit();
g_pFramework->Quit();
g_pFramework->Del();
return 0;
}
I really hope you guys can help me!
Greetings Maxlof