2

我有一个用 Allegro 4 编写的代码,并且正在将其转换为 Allegro 5,但是我遇到了 allegro 5 中不再存在的函数的严重问题,其中一个是“blit”

BITMAP *bTile; // Bitmap do tile;
BITMAP *bMapa; // Bitmap do mapa;
BITMAP *bTexturas[20]; // Vetor de bitmap das texturas;
BITMAP *bChar; // Bitmap do personagem;
BITMAP *bMario[3];
// ##########################################################

int main()
{
    int vResolucao_x = 640;
    int vResolucao_y = 480;

    init(vResolucao_x, vResolucao_y);

    BITMAP *buffer = create_bitmap(vResolucao_x, vResolucao_y);

    bTile = load_bitmap("Tiles/tile.bmp", NULL);
    bChar = load_bitmap("Tiles/mario.bmp", NULL);
    bMapa = create_bitmap(vResolucao_x, vResolucao_y);

// ############# - Carrega imagens do mario - ############
    bMario[0] = create_bitmap(vTile,vTile);
    bMario[1] = create_bitmap(vTile,vTile);
    bMario[2] = create_bitmap(vTile,vTile);
    blit(bChar, bMario[0],  0, 0, 0, 0, vTile, vTile);
    blit(bChar, bMario[1],  33, 0, 0, 0, vTile, vTile);
    blit(bChar, bMario[2],  66, 0, 0, 0, vTile, vTile);
// #######################################################

    install_int(fGravidade,5);

    fCarrega_Sprites_Mapa();
    fCarrega_Mapa();
    fMostra_Mapa();

    draw_sprite(screen, bMapa, 0, 0 );

    while (!key[KEY_ESC]) {

我的旧代码几乎没有任何东西适用于 Allegro 5,所以我正在根据我的学习进行转换,但是这个 blit 函数在 allegro 5 中找不到它,另一个我找不到你的模拟的函数是:install_int (...)

4

1 回答 1

3

Allegro 5 本质上是一个全新的库。这是一个逐行翻译,尽可能做到最好。请注意,Allegro 5 使用了一个完全不同的概念(事件循环),您应该真正花时间了解它是如何工作的,然后再开始尝试转换您的代码。

ALLEGRO_BITMAP *bMario[3];
// ##########################################################

int main()
{
    int vResolucao_x = 640;
    int vResolucao_y = 480;

    init(vResolucao_x, vResolucao_y);

    ALLEGRO_BITMAP *buffer = al_create_bitmap(vResolucao_x, vResolucao_y);

    bTile = al_load_bitmap("Tiles/tile.bmp");
    bChar = al_load_bitmap("Tiles/mario.bmp");
    bMapa = al_create_bitmap(vResolucao_x, vResolucao_y);

// ############# - Carrega imagens do mario - ############
    bMario[0] = al_create_bitmap(vTile,vTile);
    bMario[1] = al_create_bitmap(vTile,vTile);
    bMario[2] = al_create_bitmap(vTile,vTile);

    al_set_target_bitmap(bMario[0]);
    al_draw_bitmap(bchar, 0, 0, 0);

    al_set_target_bitmap(bMario[1]);
    al_draw_bitmap(bchar, 33, 0, 0);

    al_set_target_bitmap(bMario[2]);
    al_draw_bitmap(bchar, 66, 0, 0);

    al_set_target_backbuffer(display);
// #######################################################

    fGravidade = al_create_timer(5 / 1000.0); // ALLEGRO_TIMER*

    ALLEGRO_EVENT_QUEUE *queue = al_create_event_queue();
    al_register_event_source(queue, al_get_timer_event_source(gfGravidade));
    al_register_event_source(queue, al_get_keyboard_event_source());

    fCarrega_Sprites_Mapa();
    fCarrega_Mapa();
    fMostra_Mapa();

    al_draw_bitmap(bMapa, 0, 0, 0);
    al_flip_display();

    while (true) {
      ALLEGRO_EVENT event;
      al_wait_for_event(queue, &event);

      if (event.type == ALLEGRO_EVENT_TIMER) {
        // fGravidade ticked
      }
      else if (event.type == ALLEGRO_EVENT_KEY_CHAR) {
        if (event.keyboard.keycode == ALLEGRO_KEY_ESCAPE) {
          break;
        }
      }
    }
于 2013-08-12T13:30:09.780 回答