Storing Maps for My Game

Storing Maps for My Game
0

#1

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?


#2

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.


#3

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!


#4

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.


#5

post the related code.


#6
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.


#7

try using levelDataString.c_str()


#8

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