快板 5 如何隐藏/卸载位图



我正在编写一个简单的2D游戏,遇到了一个小而烦人的问题,我无法卸载位图。例如,当游戏启动时,会出现一个启动画面,其中包含一个应该在 2 秒后卸载的图像(就像在任何游戏中一样,当它启动时,我们可以看到制作它的公司的名称......2 秒后,不会卸载位图。

法典:

void SplashScreen::loadContent()
{   
    image1 = al_load_bitmap("SplashScreen/image1.png");
    image2 = al_load_bitmap("SplashScreen/image2.png");
    al_draw_bitmap(image1, 0, 0, NULL);
    al_flip_display();
    al_rest(2);
    al_destroy_bitmap(image1);
    al_flip_display();
    al_draw_bitmap(image2, 0, 0, NULL);
    al_flip_display();
    al_rest(2);
    al_destroy_bitmap(image2);
    al_flip_display();
}

感谢您的帮助和观看。

要"卸载"位图,您还需要做一些其他事情。没有"在不清除屏幕的情况下清除 1 位图"这样的事情,至少不是您想要的方式。

在这种情况下,我认为您确实想要清除全屏。

你想要这样的东西

void SplashScreen::loadContent() {   
    image1 = al_load_bitmap("SplashScreen/image1.png");
    image2 = al_load_bitmap("SplashScreen/image2.png");
    //clear screen
    clearScreen();
    //draw your splash
    al_draw_bitmap(image1, 0, 0, NULL);
    //display it
    al_flip_display();
    //wait for 2 seconds
    al_rest(2);
    //fresh new frame
    clearScreen();
    //draw this second image, I don't know what this is
    al_draw_bitmap(image2, 0, 0, NULL);
    //display it
    al_flip_display();
    //wait for 2 seconds
    al_rest(2);
    //fresh screen again
    clearScreen();
    //display it
    al_flip_display();
}

游戏的一般绘图过程是这样的
1-清除屏幕
2-绘制您想要
的一切 3-翻转显示屏
4-等待几毫秒
5-在 1 时重新启动

这样,您可以在每一帧的开头获得一个全新的屏幕。初始屏幕的唯一区别是等待 2 秒,而不是几毫秒

在程序结束时,调用 destroy_bitmap 以释放资源。

最新更新