SFML community forums
Help => Window => Topic started by: cooldog99 on March 07, 2011, 06:23:14 am
-
Ok. So...
I'm using SFML 1.6, and need help with 1 small thing.
I need to limit the user (on certain things) on key presses. basically NOT allowing them to hold a key down, a 1 time key press if you will..
Also need same with mouse.
I understand this can be achieved with using Events, however my code is NOT directly inside main function, and I cannot for some reason transfer Event through a pointer into Game code, why?
I'm basically using this method
transferring events into functions through a pointer like such.
Game::Update(sf::Event * Event)
Any ideas?
Sorry if I'm not clear enough, ask and i'll clear anything up.
Please help!
-
Erhm you should be able to. You probably doing something wrong somewhere else. Do you save away the pointer? What error do you get?
Anyway to limit the user. All you have to do is ignore the event when you don't want it.
-
Erhm you should be able to. You probably doing something wrong somewhere else. Do you save away the pointer? What error do you get?
Anyway to limit the user. All you have to do is ignore the event when you don't want it.
I know, that's what I don't get...
here, lemme show some code snippets.
FYI the code has been reduced, so you don't see our massive bulk code :p
main function
GameRun(&App, &Event);
GameDraw(&App);
void GameRun(sf::RenderWindow *app, sf::Event *event)
{
mainGame.SendVariables(event);
mainGame.Update();
}
void Game::SendVariables(sf::RenderWindow * app, sf::Event * event)
{
Window = app;
KeyEvent = event;
}
And then me trying to use it...
if (KeyEvent->Type == sf::Event::KeyPressed && KeyEvent->Key.Code == sf::Key::N)
std::cout << "N" << std::endl;
No errors, it just doesn't "catch" the event, as if it doesn't happen...
-
Ok so I'm using
extern sf::Event WindowEvent;
now, and it gets the variable from main.cpp (The main function holder) and I can access it fine inside Game.cpp (main game engine class), however, two things.
I can't use sf::Key as Key.Code identifier, only #'s, and same for Event.Type.
Also KeyRepeat is stuck ON, even though it is set to FALSE. Why?
Please, anyone? I really need help :(
-
I recommend getting friendly with your debugger and walking through your event path.
Set a breakpoint a follow the event all the way through your program to find where it gets lost.
It sounds like its working when you use a global so you must be passing it wrong or overwriting it at some point.
-
I recommend getting friendly with your debugger and walking through your event path.
Set a breakpoint a follow the event all the way through your program to find where it gets lost.
It sounds like its working when you use a global so you must be passing it wrong or overwriting it at some point.
I would use the debugger, but I'm using codeblocks, and everytime I try it hangs for a sec and says "GBD.exe" (or w/e it's called) Is not responding...