Hello, I'm currently trying to create a basic 2d platformer in C++. Recently, I was trying to implement a dash using multithreading, to have its own timers.
However, I'm unable to get multi threading working.
I have the dash and movement options located in my "Player" class. Below is the code that is throwing the error, the dash code, and the errors.
Error:
void Player::events(SDL_Event& e)
{
// If a key was pressed
if (e.type == SDL_KEYDOWN && e.key.repeat == 0)
{
if (canSDash){
switch (e.key.keysym.sym)
{
case SDLK_w: sDashDirection = 1; break;
case SDLK_s: sDashDirection = 2; break;
case SDLK_a: sDashDirection = 3; break;
case SDLK_d: sDashDirection = 4; break;
}
//this is line 28
std::thread t1(&Player::sDash, sDashDirection);
t1.join;
}
}
}
sDash Code:
void Player::sDash(int direction) {
canSDash = false;
isSDashing = true;
gravity = 0.0f;
switch (direction){
//up
case 1: break;
//down
case 2: break;
//left
case 3: break;
//right
case 4: break;
}
Sleep(sDashingTime*1000);
gravity = 0.1f;
Sleep(sDashingCooldown*1000);
isSDashing = false;
canSDash = true;
}
Errors:
.../Scripts/Player.cpp:28:58: required from here
.../bits/std_thread.h:157:72: error: static assertion failed:
std::thread arguments must be invocable after conversion to rvalues
157 | typename decay<_Args>::type...>::value,