想要一些文字在游戏中删除

想要一些文字在游戏中删除

好吧,只是有点想知道解决这个问题的技巧。

因此,我希望文本“窗口将在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;
}

最佳答案

将背景移开,并将前三个文本输出移入主循环。您需要重新绘制每个框架上的所有内容。

关于c++ - 想要一些文字在游戏中删除,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/21346873/

10-11 02:54