Hello forum.
I am attempting to make a console, or just display debug messages in a nice little format. The program is currently set up so that if you press A, S, D, or F it will display a message and in a different color. however, I want the program to display each message 10px lower than the previous message.
This is not working for me, and I'm not sure why. What I want to know is what is a good way to display messages in a game window? Games such as Quake 3 and even Crysis have used consoles where you press tilde and a 'window' pops up, but how would one go about coding such an class/function?
I know how to output messages to a file, but I'm looking for something more intuitive, as it's quite annoying to have to stop and check the file for what I'm trying to debug.
SFML - Displaying debug messages
When you say it's not working for you, what did you try, and what was the result? Drawing a line at a specific place on the screen with SFML is as easy as calling SetPosition on the Text object, so I don't really understand how this would be a difficult thing.
When you say it's not working for you, what did you try, and what was the result? Drawing a line at a specific place on the screen with SFML is as easy as calling SetPosition on the Text object, so I don't really understand how this would be a difficult thing.
What I did was set the X position of each message at 10, and the Y position at (messageNumber * 10) and on the first compile it worked, but the words were too close together, so naturally I changed the spacing by changing the multiplied value to something else. But no matter what I change it to (msgNum * 100) the spacing never changes.The color changes depending on what enum I pass to the message creation function and that works perfectly. I know what SetPosition is for, but it doesn't seem to work.
The way I'm doing it now will only allow me to view 10 messages at a time. I was wondering what would be an efficient way to display an 'infinite' amount of messages. Thats why I didn't even bother to post what I did and why it didn't work. I'm sure its something simple I'm missing or forgetting to do, but as I look through my code I can't see what I'm doing wrong. Some pseudo code or a tip is kinda what I was looking for. A general base for what I'm trying to do.
(Edit)
For some weird reason, when I close the window after testing my program it doesn't register in the VS2010 window. So any changes I make aren't even recorded. I have to clean the project every time before I recompile. Would anyone know what causes that?
You could store messages as a list of strings, and each time a message is added it is pushed to the front of the list. If you want to limit the number of "remembered" strings, then after a push check the length of the list and if it over the max, pop an old message off the back.
To draw the console, just iterate over the N most recent strings (where N is the number that will fit within the console window) and draw each string, starting at the bottom of the console window and decrementing Y by LineSpacing each time (where LineSpacing is the height of your strings plus some arbitrary padding to keep them from crowding).
If SetPosition wasn't working, then you were doing something wrong, but without seeing your code it's impossible to say what.
And what do you mean "it doesn't register in the VS2010 window. So any changes I make aren't even recorded."? What doesn't register? And what changes should be recorded? That's a pretty vague statement, so any further details you could come up with would be helpful.
To draw the console, just iterate over the N most recent strings (where N is the number that will fit within the console window) and draw each string, starting at the bottom of the console window and decrementing Y by LineSpacing each time (where LineSpacing is the height of your strings plus some arbitrary padding to keep them from crowding).
If SetPosition wasn't working, then you were doing something wrong, but without seeing your code it's impossible to say what.
And what do you mean "it doesn't register in the VS2010 window. So any changes I make aren't even recorded."? What doesn't register? And what changes should be recorded? That's a pretty vague statement, so any further details you could come up with would be helpful.
Hi! It seem right that the messages where to close, because you probably don't take into consideration the height of the strings in pixels. Normally, if stringMessage1 is at position stringPos1, stringPos2 = stringPos1 + stringHeight1 + 10.
You could store messages as a list of strings, and each time a message is added it is pushed to the front of the list. If you want to limit the number of "remembered" strings, then after a push check the length of the list and if it over the max, pop an old message off the back.
To draw the console, just iterate over the N most recent strings (where N is the number that will fit within the console window) and draw each string, starting at the bottom of the console window and decrementing Y by LineSpacing each time (where LineSpacing is the height of your strings plus some arbitrary padding to keep them from crowding).
If SetPosition wasn't working, then you were doing something wrong, but without seeing your code it's impossible to say what.
And what do you mean "it doesn't register in the VS2010 window. So any changes I make aren't even recorded."? What doesn't register? And what changes should be recorded? That's a pretty vague statement, so any further details you could come up with would be helpful.
What I meant was when I compiled the first time, everything works, but when I close the window I have to tell VS to stop debugging (pressing the stop button) in order to make the program completely close. THEN when I change something in my code (anything) and press compile and run, for some reason, if I don't clean the project first, it will run the unaltered code.
I'll give your idea a try to see if I can figure it out. Right now I'm doing something similar to that but I'm having problems somewhere and I'm sure it has to do with the array I'm using to store the messages in.
Thanks for the responses.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement