Okay Im making a Zelda clone, and Im trying to implement that iconic Zelda text box style. You know where it makes a small beep with each letter?
Any ways here is my code
My problem is in the function al_draw_text(), how do I draw each piece of char array at a time, rather than all of it? I want use text[i] as my parameter instead of just text. What should I do?
I'm not sure that will respect glyph kerning... I'd personally use ALLEGRO_USTR for this:
ALLEGRO_USTR_INFO info; const ALLEGRO_USTR* ustr = al_ref_buffer(&info, text, (size_t)i); al_draw_ustr(font, al_map_rgb(255, 255, 255), x, y, 0, ustr);
Note that that will redraw the initial letters every time, so you need to clear the textbox every frame. I certainly would not use al_rest like that. Instead, I would increment i every 10 ticks or something (and not use a loop). Or, alternatively, I'd pass the start tick and the current tick to the drawText function and have it figure out the value of i from that.
Yeah im running into problems. The beep keeps on going on, and it doesn't draw each letter one at a time, I don't know what to do.
al_draw_textf(font, al_map_rgb(255, 255, 255), x, y, NULL, "%c", text[i]);
Kris - see what SiegeLord said about kerning.
Yeah im running into problems. The beep keeps on going on, and it doesn't draw each letter one at a time, I don't know what to do.
Create a timer that beats as often as you want your letters to appear. Each time you get a timer event you increment a counter like n. Then when you draw, you draw n out of the total number of letters where n is the number of timer ticks passed since you started it. Each time you get a timer event play the sound. That should solve your problems.
Draw it like SiegeLord suggested, with al_ref_buffer or al_ref_ustr.
Kris - see what SiegeLord said about kerning.
*nods* Yeah, for variable width fonts, simply looping through all the characters isn't going to work very nicely without some extra code, though I thought I'd inject that little bit of code into the conversation as a quick "make it work right now" approach. Refinements can come afterwards.
Okay how would I go about doing that with a timer? I don't know much about them other than how to use them to regulate the FPS.
These should get you started :
http://wiki.allegro.cc/index.php?title=Allegro_5_API_Tutorials
http://wiki.allegro.cc/index.php?title=Allegro_5_Tutorial/Events
http://wiki.allegro.cc/index.php?title=Allegro_5_Tutorial/Timers
You just need to wait for a timer event, then increment n and play a beep every time you get one.
K I created a timer:
ALLEGRO_TIMER *textTimer = NULL
How do I get it to tick with each letter:
textTimer = al_create_timer(?/?); ??
I don't know what to do here.
al_create_timer
ALLEGRO_TIMER* al_create_timer(double speed_secs)
Introduced in 5.0.0
Install a new timer. If successful, a pointer to a new timer object is returned, otherwise NULL is returned. speed_secs is in seconds per "tick", and must be positive. The new timer is initially stopped.
The system driver must be installed before this function can be called.
Usage note: typical granularity is on the order of microseconds, but with some drivers might only be milliseconds.
See also: al_start_timer, al_destroy_timer
Waiting on an event queue for a timer event :