thanks
SFML Tutorial needed
Page 1 of 15 Replies - 703 Views - Last Post: 18 January 2012 - 01:37 PM
Topic Sponsor:
#1
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
thanks
Replies To: SFML Tutorial needed
#2
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?
#3
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
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
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;
}
#5
Re: SFML Tutorial needed
Posted 18 January 2012 - 12:11 PM
ok i will try that thank you
#6
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.
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote






|