Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


Omalley

Member Since 07 Aug 2012
Offline Last Active Aug 15 2012 03:37 AM

Topics I've Started

Problems with SDL Input

07 August 2012 - 05:28 AM

So, I've been working on a bit of game code on and off and I had the simplest operations working nicely, those being image loading and blitting, as well as some keyboard input to move a dummy character around. What I sometimes like to do is, while developing something, I'll turn my main.cpp file into a sandbox, until the stuff I'm doing works correctly and then I'll take the code, split it up and organize it into nice little files. Well, after such an organization, I found that the keyboard input was no longer continuous, even though my switch case is supposed to handle SDL_KEYDOWN and SDL_KEYUP. I've tried moving a bunch of things around, but I'm not able to get it to work correctly. Anyone have any ideas as to why?

game loop:

[source lang="cpp"] while (!quit) { SDL_Event event; while(SDL_PollEvent(&event)) { Chronos.GetInput(event); if(event.type == SDL_QUIT) { quit = true; } } //Chronos.Move(); ColorRect(screen, 255, 255, 255); Chronos.Show(); Blit(15, 15, img, screen); Update(screen); }[/source]

Chronos.GetInput():
[source lang="cpp"]void Player::GetInput(SDL_Event event) { SDL_PollEvent(&event); switch (event.type) { case SDL_KEYDOWN: switch(event.key.keysym.sym) { case SDLK_UP: { y -= 5; direction = FACEUP; break; } case SDLK_DOWN: { y += 5; direction = FACEDOWN; break; } case SDLK_RIGHT: { x += 5; direction = FACERIGHT; break; } case SDLK_LEFT: { x -= 5; direction = FACELEFT; break; } break; } case SDL_KEYUP: switch(event.key.keysym.sym) { case SDLK_UP: { y -= 5; direction = FACEUP; break; } case SDLK_RIGHT: { x += 5; direction = FACERIGHT; break; } case SDLK_DOWN: { y += 5; direction = FACEDOWN; break; } case SDLK_LEFT: { x -= 5; direction = FACELEFT; break; } } break; } }[/source]

Using Task Manager, I also noticed that my program seems to slowly add more memory to its Working Set getting upwards of 800k KB for no apparent reason and, if unchecked, would keep going. Does anyone know what a possible cause of this could be?

I'm sure the former is just a novice mistake, however the latter seems strange and possibly more serious.

Thanks in advance for any and all help. It is much appreciated!

PARTNERS