简体   繁体   English

如何使canvas.drawBitmap在几秒钟后消失

[英]how to make a canvas.drawBitmap disappear after a few seconds

Hi I'm fairly new to java! 嗨,我对java很新! I have a game that displays the level number on the screen as a bitmap. 我有一个游戏,在屏幕上显示级别编号作为位图。 The bitmap stays on the screen throughout the level. 位图在整个关卡中保留在屏幕上。

I wish to only display the bitmap on screen for about 2 seconds and then it will disappear. 我希望只在屏幕上显示位图约2秒,然后它就会消失。 I'm just wondering can this be done. 我只是想知道这可以做到。 I've tried a few things but never got any change. 我尝试了一些事情,但从来没有做过任何改变。 Any advice would be much appreciated! 任何建议将不胜感激!

My code: 我的代码:

    if (theLevel == 1) {

        canvas.drawBitmap(AppConstants.getBitmapBank().level1, 1, 1146, null);

    }
    if (theLevel == 2) {

        canvas.drawBitmap(AppConstants.getBitmapBank().level2, 1, 1146, null);
    }
    if (theLevel == 3) {

        canvas.drawBitmap(AppConstants.getBitmapBank().level3, 1, 1146, null);
    }

You can save the time when the level starts and then in your if statements you can also check if less than 2 seconds passed. 您可以节省级别开始时的时间,然后在if语句中还可以检查是否超过2秒。 I am assuming you are clearing the canvas somewhere in the code other wise the bitmap will stay there even if you don't call drawBitmap. 我假设您正在清除代码中的某个地方,否则即使您不调用drawBitmap,位图也会保留在那里。 I don't like this approach as it is not clean and messy, a better way would be to use a fade out animation that will display the level number then fade out after 2 seconds maybe, check out this tutorial 我不喜欢这种方法,因为它不干净和凌乱,更好的方法是使用淡出动画,显示水平数,然后在2秒后淡出,也可以查看本教程

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

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