I’m making a game in C++ that uses a library called SDL and there is an issue where when the player presses play and goes to the second scene where the bed, floor and background are there but Arthur is not, and then after a split second everything disappears and it just goes black. The project is in three coding files and they will be separate pastebin documents. This problem started after I added gravity.
Arthur is not shown because you remove his image slot before showing it.
Since you keep calling this each time, loadImage will soon restart imageIndex from 1 and start overwriting the other image slots which is why everything becomes black.
The image slot code has a lot of code repetition. You might want to consider using arrays (or a resizable container such as std::vector) and loops to get rid of that. Same for the hit boxes.
I just do this because I don’t know how to call a variable by a name made up of a string or any other way to do something like that. Also you explaining this made me fix it thank you!
and instead of repeating the code 10 times whenever you want to do something with them you just have to write it once.
For example, if you let imageIndex go from 0 to 9 instead of 1 to 10 you can use it as an array index inside loadImage so the switch could be replaced by something like: