Recently I've been trying to write my own game (clone of Space Invaders) using SDL but I had a problem with events... I have 2 events, one is emited by my timer, I use it to draw moving enemy ships. Second event is my keyboard event which I use to move my ship. When I start the game, enemy ships start to move exactly as I expect but if I press key or move mouse, they move slower. I have same problem while moving my ship, if I try to move mouse, frame rate slows down a lot. My event loop:
while(!exit)
{
while(SDL_PollEvent(&event));
{
if(event.type == SDL_QUIT) exit=true;
if(event.type == SDL_KEYDOWN)
{
switch(event.key.keysym.sym)
{
case SDLK_LEFT:
pship.move(pship.getPosition().x - 1, pship.getPosition().y);
break;
case SDLK_RIGHT:
pship.move(pship.getPosition().x + 1, pship.getPosition().y);
break;
}
}
if(event.type == SDL_USEREVENT)
{
switch(event.user.code)
{
case 1:
static int xOffset, yOffset;
xOffset++;
yOffset++;
drawEnemyShips(eship,xOffset,yOffset);
break;
}
}
}
}
I use Visual c++ 2010 express and SDL 1.2.15