1
Window / Noob question about variables in Text()
« on: May 14, 2012, 09:47:50 am »
Hi everyone,
I just got SFML installed so I was playing around with the code that the tutorial provided, I was just wondering why this code only outputs variable a and not variables a+b;
I just got SFML installed so I was playing around with the code that the tutorial provided, I was just wondering why this code only outputs variable a and not variables a+b;
#include "SFML/Graphics.hpp"
#include <string>
#include <iostream>
using namespace std;
int main()
{
string a = "hello", b="again";
sf::RenderWindow window(sf::VideoMode(600, 200), "SFML works!");
sf::Text text(a + b);
while (window.isOpen())
{
sf::Text text(a);
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
window.clear();
window.draw(text);
window.display();
}
return 0;
}
I was just trying to see if I could add strings together within text(), which I would need to do if I tried to make a game. Is it possible to do calculations inside of a function from SFML, or do I have to do the calculations first and only output the one variable that contains the result?
#include <string>
#include <iostream>
using namespace std;
int main()
{
string a = "hello", b="again";
sf::RenderWindow window(sf::VideoMode(600, 200), "SFML works!");
sf::Text text(a + b);
while (window.isOpen())
{
sf::Text text(a);
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
window.clear();
window.draw(text);
window.display();
}
return 0;
}