简体   繁体   English

Allegro 5如何隐藏/卸载位图

[英]Allegro 5 how to hide/unload a bitmap

I am programming a simple 2D game and I am encountering a small but annoying problem, I can't unload bitmaps. 我正在编写一个简单的2D游戏,遇到一个小但烦人的问题,我无法卸载位图。 For example, when the game launches a splash screen appears with an image that is supposed to unload after 2 seconds (like in any games, when it launches, we can see the name of the company that made it...). 例如,当游戏启动时,会出现一个初始屏幕,其中包含应该在2秒后卸载的图像(就像在任何游戏中一样,当它启动时,我们可以看到制造它的公司的名称...)。 After 2 seconds the bitmap isn't unloaded. 2秒钟后,位图未卸载。

Code: 码:

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();
}

Thank you for your help and your viewing. 感谢您的帮助和观看。

To 'unload' your bitmap, there are some other things you have to do. 要“卸载”位图,还需要执行其他一些操作。 There is no such thing as 'clearing 1 bitmap without clearing the screen', at least not in the way you want to do it. 没有诸如“不清除屏幕就清除1位图”之类的东西,至少不会以您想要的方式进行。

In this case I think you actually do want to clear the full screen. 在这种情况下,我认为您实际上确实希望清除全屏。

You want something like this 你想要这样的东西

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();
}

The general drawing procedure for a game goes something like this 游戏的一般绘制过程如下
1-clear your screen 1清除屏幕
2-draw everything you want 2画你想要的一切
3-flip the display 3翻转显示
4-wait a few milliseconds 4等待几毫秒
5-restart back at 1 5从1重新开始

This way you get a fresh screen at the start of each frame. 这样,您可以在每帧的开始处获得新的屏幕。 The only difference for a splash screen is you wait 2 seconds, not a few milliseconds 启动画面的唯一区别是您等待2秒,而不是几毫秒

At the end of your program, call destroy_bitmap to free the resources. 在程序结束时,调用destroy_bitmap释放资源。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM