PM:
Can you go into more detail about whats happening.
Also is there any reason you you use C Code rather than C++ for SDL ?
Game is called CPlusPlus-LettersFall but seems to be very C like.
ANSWER:
Hi,
The new image loading code works, but it’s not ideal.
I am having trouble reading individual lines of file names in a regular TXT file.
I’ll post your response in the original forum post, please continue the discussion there.
Also, yes the game’s source is mostly C code with some small C++ parts like C++ Classes.
Thanks…
If your allowing yourself to use C++ then you should use it to simplify the issue.
You have a lot going on in the LoadSpritesAndInitialize and its difficult to understand what your doing or trying to achieve. Hopefully this might help you.
Here is a quick example of what I mean.
It may not be the faster than C but it will save you a headache.
This example reads the content of a file into a stringstream.
Using the getline function we extract each line of characters into a string.
#include <fstream>
#include <sstream>
void getDataFromFile(const char* fileName, std::stringstream& ss) {
std::ifstream file(fileName);
if(file.is_open()) {
ss << file.rdbuf(); //read the file into the stringstream
}
file.close();
}
int main() {
std::stringstream ss;
getDataFromFile("../textures.txt", ss);
std::string data;
while (std::getline(ss, data)) {
// Do whatever with string
// Example
// texture = loadTexture(renderer, data.c_str());
std::cout << data << '\n';
}
return 0;
}