Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Sixoul

Pages: 1 [2]
16
Audio / Re: No music when trying to call a method from a class.
« on: October 21, 2013, 10:30:49 pm »
Thanks. I knew it was something simple.

17
Audio / No music when trying to call a method from a class.
« on: October 21, 2013, 09:46:25 pm »
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.

Pages: 1 [2]
anything