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 - JM1082

Pages: [1]
1
Audio / Re: Advice for music in different locations...
« on: March 30, 2012, 02:33:07 pm »
That's correct, but the game isn't linear, so I could be coming at a location from any number of other locations!
I was hoping there might be a way to stop all music instances with one function, but maybe there is not...  :-(

2
Audio / Advice for music in different locations...
« on: March 29, 2012, 06:54:44 pm »
Hi all!

I want different music for my game locations but I can't come up with a clever way of stopping the music of the previous location before starting the next location's music...

So, my code so far plays the first song in location1 then plays both songs together when I move to location2!

Please see my code below:
#include <iostream>
#include <SFML/System.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>

using namespace std;

int main()
{
    sf::RenderWindow gameWindow( sf::VideoMode( 800, 600, 32 ), "Hello, World!" );

    sf::Image Image, Image2;
    if ( !Image.LoadFromFile( "DN1.png" ) )
        cout << "Picture load error..." << endl;

    sf::Sprite sprite1, sprite2;
    sprite1.SetImage( Image );

    if ( !Image2.LoadFromFile( "DN2.png" ) )
        cout << "Picture load error..." << endl;

    sprite2.SetImage( Image2 );

    sprite1.SetPosition( 200.f, 250.f );
    sprite2.SetPosition( 600.f, 250.f );

    sf::Music music1, music2;
    if ( !music1.OpenFromFile( "T1.ogg" ) )
        cout << "No music 1..." << endl;

    if ( !music2.OpenFromFile( "T2.ogg" ) )
        cout << "No music 2..." << endl;

    while ( gameWindow.IsOpened() )
    {
        sf::Event Event;
        while ( gameWindow.GetEvent( Event ) )
        {
            // Window closed
            if ( Event.Type == sf::Event::Closed )
                gameWindow.Close();

            // Escape key pressed
            if ( ( Event.Type == sf::Event::KeyPressed ) && ( Event.Key.Code == sf::Key::Escape ) )
                gameWindow.Close();

            // Left key pressed
            if ( ( Event.Type == sf::Event::KeyPressed ) && ( Event.Key.Code == sf::Key::Right ) )
            {
                gameWindow.Clear();
                music1.Play();
                gameWindow.Draw( sprite1 );
                gameWindow.Display();
            } // end if


            // Right key pressed
            if ( ( Event.Type == sf::Event::KeyPressed ) && ( Event.Key.Code == sf::Key::Left ) )
            {
                gameWindow.Clear();
                music2.Play();
                gameWindow.Draw( sprite2 );
                gameWindow.Display();
            } // end if
        } // end while
    } // end while
} // end main
 

3
Graphics / Re: Sprite.GetSize() advice needed...
« on: March 29, 2012, 06:49:56 pm »
Thanks!  That's a great help!!!  ^^

4
Graphics / Sprite.GetSize() advice needed...
« on: March 21, 2012, 02:33:41 pm »
Hi all,

I want to use the Sprite.GetSize() function on a sprite I've loaded into my RenderWindow.

My sprite is called buttonTwo, so when I try to:

Code: [Select]
cout << buttonTwo.GetSize() << endl;

OR

simply calling buttonTwo.GetSize() on its own...

I'm expecting something alond the lines of pixel ranges, i.e. 1024, 600...

Instead I get a bunch of warnings talking about a Vector2f...

So I tried creating a float variable, capturing the function output into it, then displaying it:

Code: [Select]
float size = buttonTwo.GetSize();
cout << size << endl;


But still no luck...

Any suggestions would be much appreciated.

Pages: [1]
anything