0
好了,所以只是有點想知道一個訣竅來解決這個問題。想一些文字抹去自身在遊戲
所以我想文本「窗口將在10秒內關閉」通過循環抹去每次去的時間和下一個數字倒計時更換。但我現在得到的是重疊的。
我只是想爲它去它倒計時和顯示。
//FILE: Main.cpp
//PROGR: Hank Bates
//PURPOSE: To display text on screen for 10 seconds.
//EXTRA ADD ON FILES: Slendermanswriting.ttf
// PrometheusSiren.wav
#include <allegro5\allegro.h>
#include <allegro5\allegro_font.h>
#include <allegro5\allegro_ttf.h>
#include <allegro5\allegro_native_dialog.h>
#include <allegro5\allegro_audio.h>
#include <allegro5\allegro_acodec.h>
int main(void)
{
//summon the fonts and stuff
ALLEGRO_DISPLAY *display = NULL;
ALLEGRO_FONT *font50;
ALLEGRO_FONT *font36;
ALLEGRO_FONT *font18;
ALLEGRO_SAMPLE *song;
int a = 100;
if (!al_init())
{
al_show_native_message_box(NULL, NULL, NULL,
"failed to initialize allegro!", NULL, NULL);
return -1;
}
//set up some of the display settings
al_set_new_display_flags(ALLEGRO_WINDOWED | ALLEGRO_RESIZABLE);
display = al_create_display(640, 480);
al_set_window_title(display, "A bad horror game");
if (!display)
{
al_show_native_message_box(NULL, NULL, NULL,
"failed to initialize display!", NULL, NULL);
return -1;
}
al_init_font_addon();
al_init_ttf_addon();
//Install Slender Man font here
font50 = al_load_font("Slendermanswriting.ttf", 50, 0);
font36 = al_load_font("Slendermanswriting.ttf", 36, 0);
font18 = al_load_font("Slendermanswriting.ttf", 18, 0);
//set up music here
al_install_audio();
al_init_acodec_addon();
al_reserve_samples(1);
song = al_load_sample("PrometheusSiren.wav");
//play song this will loop around and around like a record man!
al_play_sample(song, 1, 0, 1, ALLEGRO_PLAYMODE_LOOP, NULL);
int screen_w = al_get_display_width(display);
int screen_h = al_get_display_height(display);
al_clear_to_color(al_map_rgb(0, 0, 0));
al_draw_text(font50, al_map_rgb(255, 0, 0), 12, 50, 0, "SLENDER MAN IS COMING");
al_draw_text(font36, al_map_rgb(255, 5, 10), 200, 100, 0, "RUN AND HIDE");
al_draw_text(font18, al_map_rgb(100, 15, 18), 150, 150, 0, "ENJOY THE PROMETHEUS SIREN MUSIC");
int timer = 10;
while (timer != 0)
{
al_draw_textf(font18, al_map_rgb(255, 255, 255), screen_w/3, 300, ALLEGRO_ALIGN_CENTRE,
"TURN UP YOUR VOLUME TO %i PRECENT!", a);
al_draw_textf(font18, al_map_rgb(255, 255, 255), screen_w/2, 400, ALLEGRO_ALIGN_CENTRE,
"WINDOW WILL CLOSE IN %i seconds!", timer);
al_flip_display();
al_rest(1.0);
timer = timer - 1;
}
al_rest(10.0);
//destroy stuff
al_destroy_font(font18);
al_destroy_font(font50);
al_destroy_font(font36);
al_destroy_display(display);
al_destroy_sample(song);
//pew pew pew, bang.... all destoryed :)
return 0;
}
在大約15年沒有用過快板自己。雖然看起來你需要使用一個位圖函數。根據文本背後的背景,在重新繪製新文本之前,您可能需要重繪一個位圖。如果它是純色,則可以將al_clear_to_color與將剪裁矩形設置爲包含需要擦除的文本的剪裁矩形結合使用。 - 這個鏈接有幫助嗎? https://www.allegro.cc/manual/5/al_clear_to_color – enhzflep
沒有位圖,所以我不知道該怎麼做,這是誠實的。 –
顯然,當您調用al_flip_display時顯示的雙緩衝區是我所說的位圖。我正在打電話,現在不能有用地查看它,但希望這會給你帶來領先。如果沒有,我會說馬修在下面說的。這就是視頻遊戲和OpenGL的工作原理 - 每一幀都重繪一切。 – enhzflep