Quote:Original post by rip-off
Quote:Original post by agi_shi
Well... Uhh... Anyone have any ideas?
how often does UpdateKeys get called. are you positive it gets called (its not accidentally in some if clause )?
other than that we'll need some code...
Every frame. Ok, here:
bool Run(){ while (mainApp.UpdateEvent()) { switch (mainApp.GetEvent().type) { case SDL_QUIT: return false; break; case SDL_KEYDOWN: { switch(mainApp.GetEvent().key.keysym.sym) { case SDLK_ESCAPE: return false; break; } } break; } } mainApp.UpdateKeys(); if (mainApp.GetKey(SDLK_LEFT)) player1.Setx(player1.Getx() - player1.GetSpeed()); if (mainApp.GetKey(SDLK_RIGHT)) player1.Setx(player1.Getx() + player1.GetSpeed()); return true;}
This is the 'so-called' core part of the problem. It's called every frame in this:
while (Run()) /*Draw my stuff...*/;
Here is the simple CApp_Input class (implementation, the declaration is simply the names of the funcs and the names of the variables...):
#include <SDL/SDL.h>#include "CApp_Input.h"CApp_Input::CApp_Input(){}CApp_Input::~CApp_Input(){}Uint8 CApp_Input::GetKey(Uint8 aKey){ return (m_pKeysHeld[aKey]);}void CApp_Input::UpdateKeys(){ m_pKeysHeld = SDL_GetKeyState(NULL);}
mainApp is a CApp. CApp inherits from CApp_Event and CApp_Input.
Like I said, returning the Uint8 doesnt work with SDLK_LEFT(or RIGHT). However, if I do it on the fly (SDL_GetKeyState(NULL)[SDLK_LEFT]) it works. And again, LEFT and RIGHT dont work and also F<whatever> and LALT and RALT. Before I never had these probs, maybe it's just me?