#include<iostream>
#include <SFML/Graphics.hpp>
usingnamespace std;
int main()
{ // Make a window that is 800 by 200 pixels
// And has the title "Hello from SFML"
sf::RenderWindow window(sf::VideoMode(800, 200), "Hello from SFML");
/** loading an image **/
sf::Texture imageSource;
if(!imageSource.loadFromFile("background.png"))
return EXIT_FAILURE;
sf::Sprite imageSprite;
imageSprite.setTexture(imageSource);
sf::Text message;
// We need to choose a font
sf::Font font;
font.loadFromFile("font.ttf");
// Set the font to our message
message.setFont(font);
// Assign the actual message
string name;
for(int i=0;i<5;i++)
{
cout<< "enter word: ";
cin>>name;
message.setString(name);
message.setString(name);
message.setCharacterSize(20);
// Choose a color
message.setFillColor(sf::Color::White);
}
// This "while" loop goes round and round- perhaps forever
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
// Someone closed the window- bye
window.close();
}
window.draw(imageSprite);
window.draw(message);
// Show everything we just drew
window.display();
}// This is the end of the "while" loop
return 0;
}
i'd like to display multiple names, but i don't know how to that ( the names will be entered using the consol)
What you can try is to store the names in a vector first.
For each name in the vector create a sf::Text,
set the name and position and call window.draw for the text.