SFML community forums

Help => General => Topic started by: URSvAir14 on February 28, 2014, 06:19:02 pm

Title: Image cache for a basic game
Post by: URSvAir14 on February 28, 2014, 06:19:02 pm
Hello All!

I already understand what a cache is, but I have a question about using one in my game. Firstly, what would be the best way to implement a cache using SFML and c++? I assume I'd need to make a collection of global textures that could be accessed from anywhere, but how should I do it?
Secondly, what kind of things should I load into the cache and what shouldn't I load? I think that I should load in the texture containing my common enemies and the texture containing different projectiles, but what other things should I be using there?

Thank you!
Title: Re: Image cache for a basic game
Post by: Nexus on February 28, 2014, 06:31:31 pm
Firstly, what would be the best way to implement a cache using SFML and c++?
Don't reinvent the wheel. My library Thor already offers a resource-managing module (http://www.bromeon.ch/libraries/thor/v2.0/tutorial-resources.html), and there's a simpler more lightweight version (ResourceHolder) in the SFML book (https://github.com/SFML/SFML-Game-Development-Book).

I assume I'd need to make a collection of global textures that could be accessed from anywhere
No. Global is mostly bad, and always in the case of SFML resource objects. You should rather think about a clean design that allows you to access textures from the places where you need them -- not from everywhere.

Secondly, what kind of things should I load into the cache and what shouldn't I load? I think that I should load in the texture containing my common enemies and the texture containing different projectiles, but what other things should I be using there?
When you already have a cache, why not load everything with it? At least the one from Thor is smart enough to recognize when you're attempting to load duplicates.
Title: Re: Image cache for a basic game
Post by: URSvAir14 on February 28, 2014, 06:34:22 pm
Okay, thanks :D