5 Replies - 703 Views - Last Post: 18 January 2012 - 01:37 PM Rate Topic: -----

Topic Sponsor:

#1 Frankma5  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 39
  • Joined: 07-January 12

SFML Tutorial needed

Posted 18 January 2012 - 11:19 AM

i need a good SFML Tutorial. I have searched for one and all i can find is the one on SFML website and i have read that but i would like one that has a bit more info about how to do different things in the one program. like have music playing and have a moving sprite with a background .

thanks :)
Is This A Good Question/Topic? 0
  • +

Replies To: SFML Tutorial needed

#2 modi123_1  Icon User is offline

  • Suiter #2
  • member icon


Reputation: 3546
  • View blog
  • Posts: 14,961
  • Joined: 12-June 08

Re: SFML Tutorial needed

Posted 18 January 2012 - 11:49 AM

Quote

i would like one that has a bit more info about how to do different things in the one program.


Would you elaborate more? Sure I got music, background, moving sprite. What else?
Was This Post Helpful? 0
  • +
  • -

#3 Frankma5  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 39
  • Joined: 07-January 12

Re: SFML Tutorial needed

Posted 18 January 2012 - 12:05 PM

well what i mean is i know how to play music and i know how to make a moving sprite but how do i do both at the same time.


here is the code of the moving sprite

////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics.hpp>

int main()
{
    // Create main window
    sf::RenderWindow App(sf::VideoMode(800, 600), "SFML Shapes");

    // Start game loop
    while (App.IsOpened())
    {
        // Process events
        sf::Event Event;
        while (App.GetEvent(Event))
        {
            // Close window : exit
            if (Event.Type == sf::Event::Closed)
                App.Close();
        }

        // Clear screen
        App.Clear();

        // Draw predefined shapes
        App.Draw(sf::Shape::Line(0, 0, 1000, 0, 500, sf::Color::Red));
        App.Draw(sf::Shape::Circle(200, 200, 100, sf::Color::Yellow, 10, sf::Color::Blue));
        App.Draw(sf::Shape::Rectangle(30, 200, 600, 350, sf::Color::Green));

        // Build a custom convex shape
        sf::Shape Polygon;
        Polygon.AddPoint(10, -10,  sf::Color(255, 0, 0),     sf::Color(0, 128, 128));


        // Define an outline width
        Polygon.SetOutlineWidth(10);

        // Disable filling and enable the outline
        Polygon.EnableFill(false);
        Polygon.EnableOutline(true);

        // We can still use the functions common to all SFML drawable objects
        Polygon.SetColor(sf::Color(255, 255, 255, 200));
        Polygon.Move(300, 300);
        Polygon.Scale(3, 2);
        Polygon.Rotate(45);

        // Draw it
        App.Draw(Polygon);

        // Finally, display the rendered frame on screen
        App.Display();
    }

    return EXIT_SUCCESS;
}



But where do i put the code for the music playing ?

the tutorial on the SFML website tells you how to do one thing at a time but it does not tell you how to do more then one thing at a time .

sorry wrong code


here is the moving sprite code
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics.hpp>


////////////////////////////////////////////////////////////
/// Entry point of application
///
/// \return Application exit code
///
////////////////////////////////////////////////////////////
int main()
{
    // Create the main rendering window
    sf::RenderWindow App(sf::VideoMode(800, 600, 32), "SFML Graphics");

    // Load the sprite image from a file
    sf::Image Image;
    if (!Image.LoadFromFile("sprite.tga"))
        return EXIT_FAILURE;

    // Create the sprite
    sf::Sprite Sprite(Image);

    // Change its properties
    Sprite.SetColor(sf::Color(0, 255, 255, 128));
    Sprite.SetPosition(200.f, 100.f);
    Sprite.SetScale(2.f, 2.f);

    // Start game loop
    while (App.IsOpened())
    {
        // Process events
        sf::Event Event;
        while (App.GetEvent(Event))
        {
            // Close window : exit
            if (Event.Type == sf::Event::Closed)
                App.Close();
        }

        // Get elapsed time
        float ElapsedTime = App.GetFrameTime();

        // Move the sprite
        if (App.GetInput().IsKeyDown(sf::Key::Left))  Sprite.Move(-100 * ElapsedTime, 0);
        if (App.GetInput().IsKeyDown(sf::Key::Right)) Sprite.Move( 100 * ElapsedTime, 0);
        if (App.GetInput().IsKeyDown(sf::Key::Up))    Sprite.Move(0, -100 * ElapsedTime);
        if (App.GetInput().IsKeyDown(sf::Key::Down))  Sprite.Move(0,  100 * ElapsedTime);

        // Rotate the sprite
        if (App.GetInput().IsKeyDown(sf::Key::Add))      Sprite.Rotate(- 100 * ElapsedTime);
        if (App.GetInput().IsKeyDown(sf::Key::Subtract)) Sprite.Rotate(+ 100 * ElapsedTime);

        // Clear screen
        App.Clear();

        // Display sprite in our window
        App.Draw(Sprite);

        // Display window contents on screen
        App.Display();
    }

    return EXIT_SUCCESS;
}


Was This Post Helpful? 0
  • +
  • -

#4 modi123_1  Icon User is offline

  • Suiter #2
  • member icon


Reputation: 3546
  • View blog
  • Posts: 14,961
  • Joined: 12-June 08

Re: SFML Tutorial needed

Posted 18 January 2012 - 12:08 PM

Well - without knowing a lick of SFML I would suppose I would try playing it before the game loop started... using (and I assume you read this one their site) the various controls and methods created in a tutorial on their site.
Was This Post Helpful? 0
  • +
  • -

#5 Frankma5  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 39
  • Joined: 07-January 12

Re: SFML Tutorial needed

Posted 18 January 2012 - 12:11 PM

ok i will try that thank you
Was This Post Helpful? 0
  • +
  • -

#6 Serapth  Icon User is offline

  • D.I.C Head


Reputation: 49
  • View blog
  • Posts: 145
  • Joined: 17-August 11

Re: SFML Tutorial needed

Posted 18 January 2012 - 01:37 PM

This tutorial series covers all of that stuff and more, shows implementing a complete game in SFML using modern C++ in a closer to "real world" style than most tutorials.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1