Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Want Text to appear gradually from Left to Right

This thread is locked; no one can reply to it. rss feed Print
 1   2 
Want Text to appear gradually from Left to Right
HappyBoy
Member #13,462
September 2011

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
Member #12,491
January 2011
avatar

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.

" There are plenty of wonderful ideas in The Bible, but God isn't one of them." - Derezo
"If your body was a business, thought would be like micro-management and emotions would be like macro-management. If you primarily live your life with emotions, then you are prone to error on the details. If you over-think things all the time you tend to lose scope of priorities." - Mark Oates

HappyBoy
Member #13,462
September 2011

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
Member #12,491
January 2011
avatar

nvm

" There are plenty of wonderful ideas in The Bible, but God isn't one of them." - Derezo
"If your body was a business, thought would be like micro-management and emotions would be like macro-management. If you primarily live your life with emotions, then you are prone to error on the details. If you over-think things all the time you tend to lose scope of priorities." - Mark Oates

alex Ioan
Member #12,015
June 2010

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

HappyBoy
Member #13,462
September 2011

To: ALEXAROTH

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

LennyLen
Member #5,313
December 2004
avatar

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
Member #1,550
September 2001

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.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Years of thorough research have revealed that the red "x" that closes a window, really isn't red, but white on red background.

Years of thorough research have revealed that what people find beautiful about the Mandelbrot set is not the set itself, but all the rest.

HappyBoy
Member #13,462
September 2011

K, no one has been helpful.

Arthur Kalliokoski
Second in Command
February 2005
avatar

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?

They all watch too much MSNBC... they get ideas.

HappyBoy
Member #13,462
September 2011

To: Arthur Kalliokoski

A demonstration of a simple example would have been good.

Arthur Kalliokoski
Second in Command
February 2005
avatar

#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}

They all watch too much MSNBC... they get ideas.

HappyBoy
Member #13,462
September 2011

Thank you, but that just returns Build Error.

Arthur Kalliokoski
Second in Command
February 2005
avatar

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

They all watch too much MSNBC... they get ideas.

Johan Halmén
Member #1,550
September 2001

Happy Boy, what can you do?

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Years of thorough research have revealed that the red "x" that closes a window, really isn't red, but white on red background.

Years of thorough research have revealed that what people find beautiful about the Mandelbrot set is not the set itself, but all the rest.

HappyBoy
Member #13,462
September 2011

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
Supreme Loser
January 1999
avatar

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
Major Reynaldo
May 2007
avatar

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
Second in Command
February 2005
avatar

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.

They all watch too much MSNBC... they get ideas.

Matthew Leverton
Supreme Loser
January 1999
avatar

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~
Member #12,192
August 2010

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.

--------------------------------------------------
http://blog.wolfire.com/2009/04/always-initialize-your-memory/

If this is possible if you don't correctly initialize memory, it should be a priority of the highest order.

bamccaig
Member #7,536
July 2006
avatar

HappyBoy
Member #13,462
September 2011

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
Member #1,550
September 2001

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.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Years of thorough research have revealed that the red "x" that closes a window, really isn't red, but white on red background.

Years of thorough research have revealed that what people find beautiful about the Mandelbrot set is not the set itself, but all the rest.

LennyLen
Member #5,313
December 2004
avatar

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.

 1   2 


Go to: