Printing numbers in Allegro
i've been having a bit of trouble with printing numbers in Allegro. At the moment i am using the textout_ex() function and replacing the string with a variable holding the number of lives the player has left, problem being it says
"invalid conversion from `int' to `const char*'"
Any help would be great.
You need to convert the number to a string. Assuming C++, you can use a std::stringstream or boost::lexical_cast. Ex:
std::stringstream sstr;sstr << my_number;const char * my_number_as_char_pointer = sstr.str().c_str()
The textprintf_ex() function provides printf style formatting, so doing any of your own conversion is a wasted effort.
int player_score;textprintf_ex(screen, font, 10, 10, makecol(255, 100, 200), -1, "Score: %d", player_score);
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement