Hi im kinda new to C++ and Allegro. And im using tutorials. But i have a problem. I Made a player class where i want a function (controls) to call in main. somehow i dont get it to work, so i put the movement in main. somehow that works but, it only moves once after pressing the button. It doesnt continue.
Can someone help me with this?
1st: how do i make the movement continues. (this is more important tho)
2nd: how do i place it in the class.
showing the main.cpp, InputManager class and Player class.
Hello,
IsKeyPressed (ALLEGRO_EVENT_KEY_DOWN) only trigger once, when you press the key.
Personally, I've a boolean array (size ALLEGRO_KEY_MAX). Every update I loop through it ; I keep in there every key state, when you press (ALLEGRO_EVENT_KEY_DOWN) => true, when you release (ALLEGRO_EVENT_KEY_UP) => false.
Maybe there is another solution? which would be useful for me, too. But I don't think so.
Yeah, what Hyllis said. So, you need to set a flag when the key_down event happens, and then reset it when the key_up event happens; here is some psuedo code: