Skip to main content
gamedev.net
🔒 Locked

Sprite Management

Started by Mad_Coder Jul 28, 2007 at 1:13 PM 2 replies 650+ views
Original Post
Mad_Coder
Mad_Coder
I am managing sprites as bundles of images as sprite sheets all in a directory. Each of these directories are an instance of a "management". My only problem is that I can not figure out how to pass all the filenames as a bundle without either having the user change the implementation of the classes constructor parameters to how many files their are or having a vector or array of std::string type objects of all the filenames, which would have to be specified somewhere elsewhere than the constructor definiion like in a header file or somewhere in the main loop which will make a mess. Does any one have an idea how can I have the user specify the filenames without every image being it being implemented somewhere out of the class's function like a main loop or header? My ideas for each file directory bundle:

//First Idea
const int numberFiles = 3;
const std::string Files[3] = { "All.png", "Your.png", "Base.png" };

// main loop
SpriteManage.SetFileNum(numberFiles);
SpriteManage.SetFileNames(&Files);

//Second Idea: Or do ^ in a header file

Zakwayda
Zakwayda
I didn't quite follow all that, but here are a couple of suggestions:

1. Make use of your class constructors. If you find that this is difficult to do (for example, because your 'sprite manager' class is global), then reconsider the scope of the object.

2. Use std::vector (or some other container class) for the file names. That way you won't have to treat the 'number of files' as a separate variable (which is awkward and error-prone).
luke2
luke2
I don't really understand your issue, but I might mention that you can use containers as parameters to methods like constructors... Or you could just create every sprite individually.. but could you please explain your issue?
Verg
Verg
Sounds like you're trying to implement some kind of a library.

I would suggest finding a script parser, or creating one yourself with something like Boost::Spirit. You can create simple parsers that read in filenames from a resource.

If you change the resource (the text file) it takes about 10 seconds to recompile and link.

You may also want to create these "filename lists" on the fly with a Perl script or something, and then parse them in C++, so that your lists can remain dynamic.

Either that or you can forget the Perl script, and just keep a list of the directories in your parsable script... and have your code read those names in and load everything in a directory.

As far as getting them into a vector, Spirit can do that for you when it parses your file list by using "closures" and the Spirit extension "Phoenix". It can automatically insert the strings into a vector of std::string.

Then you would just pass the vector into your function like this:

void foo(std::vector<std::string> &filenames);


It really isn't that bad to learn; it seems odd at first, but isn't too bad once you get going with it.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.