So right now I'm trying to get a basic idea of how to set things up.
game.cpp
#include "stdafx.h"
#include "Game.h"
#include "GameMusic.h"
int main()
{
// create the window
sf::RenderWindow gamescreen(sf::VideoMode(800, 600), "Legend of Link");
// create texture and sprite
sf::Texture texture;
sf::Sprite sprite;
// play the audio
GameMusic ingamemusic;
ingamemusic.PlayMusic();
if (!texture.loadFromFile("res/graphics/Link.png"))
{
// error...
}
else
sprite.setTexture(texture);
// run the program as long as the window is open
while (gamescreen.isOpen())
{
// check all the window's events that were triggered since the last iteration of the loop
sf::Event event;
while (gamescreen.pollEvent(event))
{
// "close requested" event: we close the window
if (event.type == sf::Event::Closed)
{
//music.StopMusic();
gamescreen.close();
}
}
// clear the window with black color
gamescreen.clear(sf::Color::Black);
// draw everything here...
// gamescreen.draw(...);
gamescreen.draw(sprite);
// end the current frame
gamescreen.display();
}
return 0;
}
GameMusic.cpp
#include "GameMusic.h"
int GameMusic::PlayMusic()
{
sf::Music music;
if (!music.openFromFile("res/audio/music/Vengeance.ogg"))
return -1; // error
music.setVolume(100);
music.play();
}
So when I take the PlayMusic() and put it into Game.cpp it runs fine. But when I try to call the method for it to do the same thing it doesn't play the music. Am I forgetting something? I feel like it would be something super simple too.