Jump to content
  • Advertisement
Sign in to follow this  
vaironl

Allegro - Printing X & Y coordinates to the screen

This topic is 2517 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello forum, right now I'm challenging myself to make a good allegro basic circle movement without any tutorials .
So there is one thing that I want to implement into my code and that is, printing the x and y coordinates to the screen. For multiple purposes .

I tried the textout but I really don't know how to make the program print the variable , here is what I tried.



textout(buffer, font, "this is x" << x , "this is y" << y , 0, 0, makecol(0, 250, 30) , -1);


Share this post


Link to post
Share on other sites
Advertisement

I tried the textout but I really don't know how to make the program print the variable , here is what I tried.

textout(buffer, font, "this is x" << x , "this is y" << y , 0, 0, makecol(0, 250, 30) , -1);
1--^ 2--^ (3) 4--^ 5-^



1) A c-string isn't a stream. In C and C++, one cannot concatenate strings natively. One must either use strcat/sprintf (C) or stringstreams (C++)
2) The comma operator separates parameters, this means the compiler is expecting an integer for (3)
3) The compiler expects an integer for the fourth parameter
4) A c-string isn't a stream.
5) Because of the extra parameter at (2), this is treated as an extra parameter.


What you want to do is use stringstreams:


#include <sstream>

stringstream ss;
ss << "x=" << x << ", " << "y=" << y;
string temp = ss.str();
textout( buffer, font, temp.c_str(), 0, 0, makecol( 0, 250, 30 ), -1 );

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!