That makes a bit more sense, but if I have multiple unique sprites along with music, and fonts in my LoadMedia() function, how would I handle that?
I realize I should have put that into the first bit of code, but I thought it would be a standardized solution, not handling each one separately.
--Using your way would mean using "sf::Sprite* Title = LoadMenu();" multiple times for multiple objects. While I haven't tried it, I have a feeling that wouldn't work as intended.
For example:
int LoadMedia();
int Menu(sf::Sprite*, sf::Sprite*, sf::Sprite*, bool, sf::Music*);
int Game(sf::String*, sf::Music*, sf::Sprite*, sf::Sprite*, sf::Sprite*, sf::Sprite*);
int main() {
LoadMedia();
Menu(Title, Easy, Hard, MouseLeftDown, MenuMusic);
Game(HealthText, GameMusic, playerSprite, World1, World2, spacestationSprite);
}
int LoadMedia () {
//Picture Data --------------------------------------------------
sf::Image ITitle;
if(!ITitle.LoadFromFile("media/images/UI/title.png")) {return EXIT_FAILURE;}
sf::Sprite Title(ITitle);
Title.SetCenter(221,51.5);
sf::Image difficultyImage;
if(!difficultyImage.LoadFromFile("media/images/UI/difficulty.png")) {return EXIT_FAILURE;}
sf::Sprite Easy(difficultyImage); //Easy
Easy.SetSubRect(sf::IntRect(0,0,200,50));
Easy.SetCenter(100,25);
sf::Sprite Hard(difficultyImage); //Hard
Hard.SetSubRect(sf::IntRect(0,100,200,150));
Hard.SetCenter(100,25);
//Music Data -----------------------------------------------------------------
sf::Music MenuMusic;
if(!MenuMusic.OpenFromFile("media/music/The Son of Flynn.ogg")) {return EXIT_FAILURE;}
sf::Music GameMusic;
if(!GameMusic.OpenFromFile("media/music/Separate Ways.ogg")) {return EXIT_FAILURE;}
// Text Data -----------------------------------------------------------------
sf::Font MyFont;
if (!MyFont.LoadFromFile("media/Bedizen.ttf", 25)) {return EXIT_FAILURE;}
sf::String HealthText;
HealthText.SetFont(MyFont);
HealthText.SetColor(sf::Color::Black);
HealthText.SetSize(20);
}
int Menu (sf::Sprite* Title, sf::Sprite* Easy, sf::Sprite* Hard, bool MouseLeftDown, sf::Music* MenuMusic) {
(*MenuMusic).Play();
(*Title).SetPosition(Menu.GetWidth()/2,100);
(*Easy).SetPosition(Menu.GetWidth()/2,340);
(*Hard).SetPosition... yadda yadda yadda
Menu.Draw(*Title);
Menu.Draw(*Easy);
Menu.Draw(*Hard);
}