Sign in to follow this  

Allegro - Printing X & Y coordinates to the screen

This topic is 2306 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.

[code]

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

[/code]

Share this post


Link to post
Share on other sites
[quote name='vaironl' timestamp='1313026566' post='4847439']
I tried the textout but I really don't know how to make the program print the variable , here is what I tried.
[code]
textout(buffer, font, "this is x" << x , "this is y" << y , 0, 0, makecol(0, 250, 30) , -1);
1--^ 2--^ (3) 4--^ 5-^
[/code]
[/quote]

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:

[code]
#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 );
[/code]

Share this post


Link to post
Share on other sites

This topic is 2306 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this