Printing chars

Started by
5 comments, last by Fender148 23 years, 8 months ago
I have a text file, I want to print a character one at a time, with a tiny delay like scrolling text, from it to the screen, its a directx application, and Im using a function from LaMothe''s book that takes a char * , an example would be Draw_Text_GDI("hi Im writing text", x, y, RGB(0,255,0), lpddsprimary); Anyway I could get this to work? or any other way? Ive tried and all out of ideas, char''s have always confused me. thanks
Advertisement
Create your own function. Basically:

void Slow_Text(unsigned int interval, char *text, ...)
{
int i = 0;

if (!strlen(text)) return;

for (;Sleep(interval), (i++) < strlen(text)
{
Draw_GDI_Text(text[(i++)], ...);
}
}

Of course it can be optimized, off the top of my head but you get the idea.

-----------------------------

A wise man once said "A person with half a clue is more dangerous than a person with or without one."

Edited by - immaGNUman on August 27, 2000 1:58:31 AM
-----------------------------A wise man once said "A person with half a clue is more dangerous than a person with or without one."The Micro$haft BSOD T-Shirt
Load the text you want to display into a single char array, then keep a running index of which character you are on. Each frame call a function like "update_text()". In the function, make it figure out if its time to show the next character or not. If it is, increment the character index by one.

To figure out if it is time to show the next character, store a variable like "lastshow" which holds the time that the last character was shown. You then compare that variable to the current time. You could encapsulate the whole thing in a "ScrollText" class if you wanted...

Hope that helped.


- Daniel
VG Games
- DanielMy homepage
Thanks for you help guys, but my main problem is the actual reading of the char from the file, not displaying it
reading a file? thats it?

Why did you give us all this extraneous information and a title that said nothing like that.... anyway:

FILE *file;

if ((file = fopen(filename, "r")) == NULL)
{
Error
}

fread(...);

fclose(file);

-----------------------------

A wise man once said "A person with half a clue is more dangerous than a person with or without one."
Thanks, but I know how to read the file, I dont know how to put the character on the screen in directx, the function Im using takes a char *, and Im having trouble with that
Sorry I said the wrong thing, my problem is displaying the char from the file, not reading from the file, very sorry

This topic is closed to new replies.

Advertisement