SFML community forums
Help => General => Topic started by: Vect0rZ on July 29, 2014, 11:22:59 am
-
Hey,
I'm new around theese forums and lately been using SFML(C++).
I did some stuff, but now I'm wondering something:
Let's say I got a class Levels{}; with some properties like: name, background sprite, number of objects, height, width... .
And class Objects with allmost the same properties wich i will use in the level.
So,
Now let's say my game have like 200 levels (only example), how should I store properly the info?
1. Should i load all those levels before game start?
2. If i have to load them one by one, should i store them somehow in a class or functions and call them on certain conditions?
Thanks in advance! =]
-
Store your levels in files.
Unless you have a reason to load every level at once, only load the level you need when you need it.
-
Thanks for the fast reply.
Excuse me, but you mean like using ostreams, and reading the data from there?
Like
Name["Level1"];
Background [Resources/level1.png];
-
What I do, for most of my projects, is to create my maps with the Tiled (http://www.mapeditor.org/) map editor and save as JSON. Then I use picojson (https://github.com/kazuho/picojson) to parse the map files and read various properties.
And at the start of each level I destroy any data related to the previous level and load the current one - keeps mem usage down and it only takes a few ms to load and parse a new level.
Regarding how to load the data from file to memory; use std::ifstream, fread or what ever else suits you - that's a detail.