Storing Maps for My Game

I want to store 100 maps or so internaly (shipped with the app).

My idea was to create a new folder “maps/” in the “Resource” folder and putting all my maps in there.

I then can load these maps using FileUtils to load and later parse them.

Issue:
How do I get into the internal storage (platform independent) to then load the maps with FileUtils?

I think you are looking for

auto path = cocos2d::FileUtils::getInstance()->fullPathForFilename(“maps/ABC.MAPFILE”)
cocos2d::FileUtils::getInstance()->getStringFromFile(path);
// OR
cocos2d::FileUtils::getInstance()->getStringFromFile(path,[](std::string content){ }); // this will be async

you shouldnt load all maps into the ram if you dont need them yet, the loading of them should be fast enough to do it just when you need them.

2 Likes

you shouldnt load all maps into the ram if you dont need them yet, the loading of them should be fast enough to do it just when you need them.

Yes of course. My maps arent that huge.
Thanks for your answer!

Actually it does not work for me.

Loading and logging the string just shows the “unknown character” in the console and not the actual string from the file.

post the related code.

std::string path = FileUtils::getInstance()->fullPathForFilename("maps/1.txt");
	std::string levelDataString = FileUtils::getInstance()->getStringFromFile(path);
	log("%s", levelDataString);

“1.txt” is located in a folder “maps” in the Resource folder.

The path is not the issue for sure.

try using levelDataString.c_str()

1 Like

Yes this is working. Thank you :slight_smile:
I am rather new to c++ :slight_smile: