Hi, i have been learning C++ and SFML and have been wondering a few things.
1) In the event tutorials the code
sf::Event event;
gets placed inside of the
while (window.isOpen()) {
loop but wouldn't this mean is is created many times? I would have expected it to get added after the RenderWindow was made at the top.
2) Also in the examples it uses sf:: but can this be removed with a "using namespace" so something like
sf::Text text("Hi", font);
would then be
Text text("Hi", font);
When i have used this with some simple examples for std:: i think doing that made the code seem simpler. Does it remain in the examples to help avoid name conflicts or something?
3) I notice that with C++ i can't just combine a string and int ("Hello" + 123 etc) which is simple with many other programming languages, i figured out the solution by using ostringstream however it then made what is normally a 1 line of code into about 4 instead.
For example i was originally expecting this type of code to work -
// Mouse wheel moved
if (event.type == sf::Event::MouseWheelMoved) {
text.setString("Mouse wheel moved" + event.mouseWheel.delta);
}
but it seems to instead cut off letters like it's a substring.
So i fix it with -
if (event.type == sf::Event::MouseWheelMoved) {
ostringstream d; d << event.mouseWheel.delta;
text.setString("Mouse wheel moved " + d.str());
}
So for more complex things you then need to use more code. I looked in the string class reference but didn't notice anything, does SMFL have any simple way/function to do this?
Thanks