I have a generic problem I suppose.
I`m currently learning C++ and SDL 2.0. SDL provides a function which returns a pointer to a const uint * containing all the keystates.
These are the variables I would like to use:
const Uint8* oldKeyState;
const Uint8* currentKeyState;
In the construction of my input.cpp:
currentKeyState = SDL_GetKeyboardState(&this->length);
oldKeyState = currentKeyState;
And in the Update() method I use:
oldKeyState = currentKeyState;
currentKeyState = SDL_GetKeyboardState(NULL);
However, instead of copying over the last values, all I do is giving a pointer to the oldKeyState, which in turn points to the current keystates..
So how do I go about copying the actual values from the variable's pointer to the current and old keystate? I don't want the pointer in my old keystate since I will not be able to check whether the previous state was UP and the new state is DOWN.
Uint8 oldKeyState[SDL_NUM_SCANCODES];
// ...
memcpy(oldkeystate, currentKeyState, length);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With