如何在屏幕上显示图片,几秒钟后自行删除?

时间:2012-01-08 05:47:10

标签: android timer andengine

如何在屏幕上显示图片,几秒钟之后删除自己? 就像游戏开始时的教程一样,我知道计时器处理程序是我应该考虑的,但是怎么能这样呢?

1 个答案:

答案 0 :(得分:4)

TimerHandler是一个简单的选择。

final Sprite picture = ...
....
TimerHandler removeHandler = new TimerHandler(secondsToRemove, new ITimerCallback() {
    @Override
    public void onTimePassed(final TimerHandler pHandler) {
        picture.unregisterUpdateHandler(pHandler);
        picture.setVisible(false);
        //Or:
        scene.detachChild(picture);
        //You should use the second option, as making the picture invisible does not detach it from your game.
    }
});
picture.registerUpdateHandler(removeHandler);