如何在Java中设置可见性false之前显示gif?

时间:2014-03-22 04:52:50

标签: java wait gif intersect

好吧,所以我目前正在为太空入侵者编码。基本上,当敌人被导弹击中时(已经编码并起作用,但如果绝对必要则可以发布)我想让它播放爆炸动画然后将其可见性设置为假,这也将从帧中移除它。我无法弄清楚如何做到这两点,我宁可玩GIF然后它会卡在最后一帧而不会消失,或者只是立即删除它并跳过gif。

这是我的董事会课程(小组)所拥有的内容

public void paint(Graphics g){
    super.paint(g);
    Graphics2D g2d = (Graphics2D) g;
    for (int i=0; i<enemies.size(); i++){
        Enemy e = (Enemy)enemies.get(i);
        if(e.isVisible())
        g2d.drawImage(e.getImage(), e.getX(),e.getY(), 45,45, this);
    }
    if(friendly.isVisible()){
        g2d.drawImage(friendly.getImage(), friendly.getX(), friendly.getY(), 40, 40, this);
    }
}



if (r3.intersects(r4)){ //Missile Hitting Enemy
    m.setVisible(false);
    bullets++;
    Bullets.setText("Bullets: " + bullets);
    e.explode();

    if(Enemy.called){
        e.setVisible(false);
        enemies.remove(j);
    }
    Resources.enemyHit.play();
    Score++;
    score.setText("Score: " + Score );
}

和我的敌人类方法:

private boolean visible = true;
private Image image;
public static boolean called = false;

public void explode(){
    Toolkit t = Toolkit.getDefaultToolkit (); //Code for Created Several Instances of a GIF
    image = t.createImage(this.getClass().getResource(explosionGif));
    called = true;
}

public void setVisible (boolean visible){
    this.visible = visible;
}

0 个答案:

没有答案