Want Text to appear gradually from Left to Right
HappyBoy

In most RPGs, text appears gradually in the textbox from left to right for more fluid reading, but I only know how to output a text fully all at once.

Here is an example of what I mean (FF7): http://www.youtube.com/watch?v=k18Jc-O2NT4

How can I display text this way in my game?

Thank you.

EDIT: I'm using Allegro 4.2.3

J-Gamer

You would have to draw one extra letter each frame(or every 3 frames or so, to reduce the speed).
So store the text, but send only render part of it. You will need a variable that holds the current amount of text to display.

HappyBoy

I'm sorry, I should have said, I'm a super noob. I don't know what you just said. Could you please demonstrate using a simple example?
I appreciate your help.

J-Gamer

nvm

alex Ioan

It means that if you can't recreate a typewriter text output effect, you need to study game design more

HappyBoy

To: ALEXAROTH

Ya, that's what I'm trying to do here.

LennyLen
HappyBoy said:

Ya, that's what I'm trying to do here.

Try breaking the problem down into small simple steps, then tell us how you think the problem should be approached. People can give you feedback on that and get you started on your way.

Simply asking people to just give you code won't help you learn much.

Johan Halmén
HappyBoy said:

but I only know how to output a text fully all at once.

Make your own function. Call it with your string as an argument, plus everything else you need, like colours and coordinates.
In your function, make a loop for(n = 0; n < length_of_your_string; n++), copy n characters from your string and output them, wait a small delay time and loop.
I'm afraid people here think that if you can't figure out this by yourself, you need to step back lots of steps and try to program something more simple. I'm afraid I agree with them.

HappyBoy

K, no one has been helpful.

Arthur Kalliokoski

W
Wh
Wha
What
What d
What di
What did
What did y
What did yo
What did you
What did you e
What did you ex
What did you exp
What did you expe
What did you expec
What did you expect
What did you expect?

HappyBoy

To: Arthur Kalliokoski

A demonstration of a simple example would have been good.

Arthur Kalliokoski
#SelectExpand
1#include <stdio.h> 2#include <string.h> 3 4int main(void) 5{ 6 char srcbuff[64] = "What did you expect?"; 7 char diffbuff[64]; 8 int i; 9 10 for(i=0;;i++) 11 { 12 strcpy(diffbuff,srcbuff); 13 diffbuff[i] = 0; 14 printf("%s\n",diffbuff); 15 if(srcbuff[i] == 0) 16 break; 17 } 18 return 0; 19}

HappyBoy

Thank you, but that just returns Build Error.

Arthur Kalliokoski

So you don't know how to use your compiler, either? You need to find some basic "Hello World" tuturial and work your way up to graphical games. Gotta walk before you run and all that.

Check this out.

http://neuron-ai.tuke.sk/~hudecm/Tutorials/Gaming/www.gametutorials.com/purpose.htm

Johan Halmén

Happy Boy, what can you do?

HappyBoy

I wish I knew why the peers in this community assume that I'm lazy just because I tried and failed then had to ask help.
The code you pasted does not compile in Win32 Application, which is where games are made. It compiles in Console Application, but Console Application is useless unless we're making a purely text-based game I thought. This is an Allegro forum, so I thought that went without saying. If not, then I owe an apology.

I don't know how to make the text "typewrite" in my Win32 Allegro game and would probably learn by example if I saw a code that actually works. That's all. People here say it's so simple, but no one here can showcase a simple working example, wtf???

So, we need it to be in Win32 Application, display on a graphics screen, and probably looks something like:
"textprintf_ex(Buffer , font , 100 , 100 , makecol(255,255,255) , -1 , "%s" , displaythismuch.c_str())" or something.

P.S. this is my working version in Console App, but it doesn't work in Allegro Win32 and doesn't work on a timer (I dunno how to do that just yet):

#include <iostream>
#include <string>
using namespace std;
int main(){
string characterphrase("I expect an example that works");
string displaythismuch(characterphrase.length(),0);
int displaycounter = 0;
while(characterphrase.compare(displaythismuch)){
displaythismuch[displaycounter] = characterphrase[displaycounter];
cout << displaythismuch;
cin.get();
displaycounter++;
}
}

Dudes, I can do lots of stuff. I'm making an RPG that presently has displayed HP/MP , random damage, string dialogue, sprite cycling, camera scrolling, random battle system, and more. I've made it from scratch and it all compiles and runs in Win32 Application just fine. I can send it to you if you want.

Matthew Leverton

This is simple, yes. But programming isn't about copy and pasting an example into your own code and expecting it to work. You must learn to figure out how to write code when people explain things to you.

Your game should have a timer system that ticks X times per second, controlling the speed of the game. If you don't do that or understand how that works, then you won't understand what we're saying.

In fact, once you understand that core principle, every thing like this becomes trivial.

char message[1000];  // the message to display piece by piece.
int len = 0;         // how much to display

// every timer tick:
len += 1;

Now only display up to len characters of the message. Exactly how you do that depends if you use C or C++ or Allegro 5 strings, etc.

If your game ticks at 60 times per second, you'll get 60 letters per second with the above message. If you want more fine control, you could easily just change len to a float and change 1 to be higher or lower depending if you want it to be faster or slower.

Edgar Reynaldo

You can easily do this by setting the clipping rectangle when you draw your text on screen. Simply keep track of how much of the text to show as a percentage or as a number of pixels per second. Use a timer so you know how much time has passed so you know how much to show and set the clipping rectangle accordingly.
See set_clip_rect.

Arthur Kalliokoski

Or if you do expect to copy and paste stuff into a game, just download the Doom or Quake source code, stick your name on it, and tell everyone you wrote a game.

Matthew Leverton

You can easily do this by setting the clipping rectangle when you draw your text on screen.

As you see, this method also relies on timers. There's many different ways to do this... all of them quite simple to implement if you understand how how basic game timing works.

North~

Make your own function. Call it with your string as an argument, plus everything else you need, like colours and coordinates.
In your function, make a loop for(n = 0; n < length_of_your_string; n++), copy n characters from your string and output them, wait a small delay time and loop.
I'm afraid people here think that if you can't figure out this by yourself, you need to step back lots of steps and try to program something more simple. I'm afraid I agree with them.

I'm confused HappyBoy... How is that not helpful? That's the entire answer written out for you clear as the sky on a bright sunny day. If you've truly implemented all of the things in your game that you said you have, this concept should've been so easy, you wouldn't have even had to post here in the first place.

bamccaig
HappyBoy

I'm not copy/pasting code into my game. I'm copy/pasting it into a blank Win32 document linked to alleg.lib, because if a code doesn't work in that environment, then it won't work anywhere.

Nope, nobody's code here even builds successfully, let alone accomplishes the desired task. I'm guessing that every poster here doesn't even really know how to do it and is too ashamed to admit it, because so far everyone says it's super easy but then can't even execute it faithfully themselves. That'd be like if they said, "I could run a marathon so easily, but I just don't feel like it."

I've since got my own way to sorta work, but it's not very efficient to do a whole game this way. Maybe I'll end up teaching everyone here after I polish it up a bit. Hah, now that would be ironic.

Johan Halmén

Nobody's code builds successfully, because they expect you to understand the essential parts in the code and copy them into your application.

Arthur's code seems quite ok. But it probably outputs something in the console window, something he posted a bit earlier. Your task is to pick the essential lines from his code into your program. I guess it would be the following lines. srcbuff is a C string containing your text to be output. diffbuff is a C string of same size, which you have allocated.

  for(i=0;;i++)
  {
    strcpy(diffbuff,srcbuff);
    diffbuff[i] = 0;
    printf("%s\n",diffbuff);
    if(srcbuff[i] == 0)
      break;
  }

Line 5 is your printing line. Replace it with your textprintf_ex(). And add a line like rest(100); to delay for a 10th of a second.

To be able to use strcpy() you have to #include <string.h>
And to be able to use rest(100); you have to install the timer.

LennyLen
HappyBoy said:

I'm guessing that every poster here doesn't even really know how to do it and is too ashamed to admit it

Sorry kid, people aren't stupid enough to fall for that one.

l j

Yep, nobody here knows how to do basic stuff at all.
Everything in the depot just magicly appeared here.

Oh and if you can code a rpg, then making this typewriter effect should be no challenge at all.

And a tip, since you are using C++, check string::substr. If you can't manage to get it working with this function...

HappyBoy

To: LennyLen

Huh? Fall for what? I'm actually being serious. See for yourself, son. Nobody has helped so far and I suspect it's because they genuinely don't know how to do it - which is perfectly acceptable, I just wish they'd stop saying it's so easy and/or I'm such a n00b when they themselves can't even do it. They type hypothetical stuff, but when I ask them to demonstrate, they choke and run off. Other people try to type code but it's dead wrong - you can tell just by looking at it.

To: Tarron

Well that's obviously wrong, bro, about as wrong everybody else's replies to this thread, because I'm running and contributing to my RPG as we speak, and I still don't know how to make a (decent) typewriter effect.

LennyLen
HappyBoy said:

Nobody has helped so far

They have, you're just too stubborn and obnoxious to recognize the help. Nobody is going to write it for you, but if you attempt to do it yourself, and post the results, people will recognize that you have made an attempt and will help you fix it.

It's up to YOU to do most of the work, nobody else.

You probably won't get much help any more though, as you have the attitude of a spoiled brat.

gnolam

I was going to say "Man, this poster is worse than that HP guy!", but then I realized they were in fact one and the same...

HappyBoy

Oh I've come to realize that I probably won't get much help, but I think it's because I'm actually a better C++ programmer than anybody else on this thread, which believe me is really sad.

LennyLen

Yes it is sad that you believe that.

Don't let the door hit you on the way out... actually, on second thoughts, do let it.

HappyBoy

Johan, do you mean like this? Because this does not work. I haven't added the PrintOut or the Rest just yet, because my compiler is underlining the two strings inside the parentheses.

#include <iostream>
#include <allegro.h>
#include <time.h>
#include <ctime>
#include <stdlib.h>
#include <string>

int main ()
{

int i = 0 ;

std::string diffbuff ("Hello world!");

std::string srcbuff("Hello world!");

for(i=0;;i++)
{
strcpy(diffbuff,srcbuff);
diffbuff[i] = 0;
printf("%s\n",diffbuff);
if(srcbuff[i] == 0)
break;
}

readkey ();
return 0;
} // End Main Function.

END_OF_MAIN ()

Thread #608300. Printed from Allegro.cc