ok then thanks oh and when you say you made console games what do you mean (game example). i made akinda weired one that predicted your future bases on a series of info u input but does that count as`a console game? give a example of what you made let me see if i could make it
console error says: Failed to load font "testtext.txt" (unknown file format)
what is a known file format under SFML?
i havent reached that part in sfml yet but i think because you closed the file name i double quotes its not recognizing as a file name but a string literal
#include <fstream> lets you read/write to/from files but i think your using it incorrectly
i havent reached that part in sfml yet but i think because you closed the file name i double quotes its not recognizing as a file name but a string literal
File names are always some sort of string. LoadFromFile expects a std::string, which can be constructed from a string literal.
@zander
mini meaning MINI....main menu, store buying crap, selling it back for less, making it all look nice in console with characters....its all just a bunch of crap code thrown together as i was learning C++ it doesnt make sense as you go through it but it did what i wanted it to do(some things that should be classes and are not.) as i learned a new thing , i would implement it into the code, so there is a little bit of everything in there, its too much of a pain in the ass though, thus my quest for something else (in this case SFML)
speaking of which, are there others like SFML (for linux and windows) and which are compatible with linux?
@Athar
that one section of code was an example that opened a file , and i just thought that i would learn how to do it by changing it lol, guess not. ill play around with file handling in console first then, thanks.
I'm a little late on this one. I'm not sure if you figured this out already, but...
type some text and named it testtext.ttf (in which it changed to a .ttf file) (which i have no idea also what a .ttf file is?) then i threw that file into the files with this .cpp file below , then i just took out their named file and put in my own, but it wont load the file?
SFML doesn't help with reading text files. It only helps with reading resource files like fonts, music, images.
If you want to read text from a file and draw it on screen, you'll need to read the text into a string on your own, first, then give that string to an sf::Text object.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#include <fstream> // for ifstream
#include <string> // for string
//...
// simplified example, assuming the file is only 1 line of text
std::ifstream myfile("mytextfile.txt"); // open the file
std::string mystring;
std::getline( myfile, mystring ); // read the line of text from the file, put it in my string
sf::Text mytext(mystring); // give the string to an sf::Text object
// 'mytext' can now be drawn
You were trying to load your text file as a font file, which wasn't working. Font files hold information about a font (like arial, calibri, tahoma, verdana, etc -- all those fonts available in MSWord and other programs... those are all stored in font files on your computer. If you want to display your text in a specific one of those fonts, you would load that font with sf::Font::LoadFromFile -- but that doesn't do anything to indicate which text you want to display -- only the font used with which to display it)
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <SFML/System.hpp>
#include <fstream> // for ifstream
#include <string> // for string
int main()
{
// simplified example, assuming the file is only 1 line of text
std::ifstream myfile("test2.txt"); // open the file
std::string mystring;
std::getline( myfile, mystring ); // read the line of text from the file, put it in my string
sf::Text mytext(mystring); // give the string to an sf::Text object
// 'mytext' can now be drawn
sf::RenderWindow window(sf::VideoMode(800, 600),"New Window");
while(window.IsOpened())
{
sf::Event Event;
while (window.GetEvent(Event))
{
// Close window : exit
if (Event.Type == sf::Event::Closed)
window.Close();
}
window.Clear();
window.Draw(mytext);
window.Display();
}
return EXIT_SUCCESS;
}// end main
but i get an error that Text is not a member of sf::?
Did you get SFML 2.0 or 1.6?
sf::Text is in 2.0 only (in 1.6 it was sf::String). If you got 1.6 I highly recommend updating. 2.0 has way more features and is more stable, even if it's still in development.
so if i wanted to display the text in the window, and then duplicate the same text under the previous text, how would i do that ?
my first instinct after coming from using the console is to put endl after the first (mytext) . so i how would i adjust the second mytext location on the screen? Where might i find explanation of this?
1 2
window.Draw(mytext);
window.Draw(mytext);
im guessing that the second one is overlapping the first? not sure though? so i am assuming that i have to move the second one over(anywhere) to be visable. is this the wrong thought process about this?
first i double the window.Draw(mytext);
1 2
window.Draw(mytext);
window.Draw(mytext);
and nothing but one line?
then i doubled the whole while loop to see what it would do , but again only the one line.
while(window.IsOpened())
{
sf::Event Event;
while (window.GetEvent(Event))
{
// Close window : exit
if (Event.Type == sf::Event::Closed)
window.Close();
}
window.Clear();
window.Draw(mytext);
window.Display();
}
while(window.IsOpened())
{
sf::Event Event;
while (window.GetEvent(Event))
{
// Close window : exit
if (Event.Type == sf::Event::Closed)
window.Close();
}
window.Clear();
window.Draw(mytext);
window.Display();
}
and if i put a paragraph in the text file it will only get line 1?
how would you difplay an entire paragraph?
this is so confusing, i could see why this could take years to learn decent programming lol