0
我試圖讓我的遊戲中發生爆炸,發生地雷炸彈。目前我有一個int來存儲要繪製的圖像。我希望它每隔0.5秒更新一次圖像,但目前通過它們循環如此之快,你真的看不到爆炸。每隔0.5秒就有什麼方法可以擴展此實現來獲取更新?java遊戲中的爆炸效果
這裏是繪製方法:
@Override
public void draw(Graphics2D g) {
if (imageNum == 0){
sprite = new Sprite(Sprite.MINE,this.position,new Vector2D(0,0),this.radius,this.radius,0);
}else if (imageNum == 1){
sprite = new Sprite(Sprite.MINE1,this.position,new Vector2D(0,0),this.radius,this.radius,0);
this.radius = sprite.getRadius();
imageNum ++;
}else if (imageNum == 2){
sprite = new Sprite(Sprite.MINE2,this.position,new Vector2D(0,0),this.radius,this.radius,0);
this.radius = sprite.getRadius();
imageNum ++;
}else if (imageNum == 3){
sprite = new Sprite(Sprite.MINE3,this.position,new Vector2D(0,0),this.radius,this.radius,0);
this.radius = sprite.getRadius();
imageNum ++;
}else if (imageNum == 4){
sprite = new Sprite(Sprite.EXPLOSION_4,this.position,new Vector2D(0,0),this.radius,this.radius,0);
this.radius = sprite.getRadius();
imageNum ++;
}else if (imageNum == 5){
sprite = new Sprite(Sprite.EXPLOSION_5,this.position,new Vector2D(0,0),this.radius,this.radius,0);
this.radius = sprite.getRadius();
imageNum ++;
}else if (imageNum == 6){
sprite = new Sprite(Sprite.EXPLOSION_6,this.position,new Vector2D(0,0),this.radius,this.radius,0);
this.radius = sprite.getRadius();
imageNum ++;
}else if (imageNum == 7){
sprite = new Sprite(Sprite.EXPLOSION_7,this.position,new Vector2D(0,0),this.radius,this.radius,0);
this.radius = sprite.getRadius();
imageNum ++;
}else if (imageNum == 8){
sprite = new Sprite(Sprite.EXPLOSION_6,this.position,new Vector2D(0,0),this.radius,this.radius,0);
this.radius = sprite.getRadius();
imageNum ++;
}else if (imageNum == 9){
sprite = new Sprite(Sprite.EXPLOSION_5,this.position,new Vector2D(0,0),this.radius,this.radius,0);
this.radius = sprite.getRadius();
imageNum ++;
}else if (imageNum == 10){
sprite = new Sprite(Sprite.EXPLOSION_4,this.position,new Vector2D(0,0),this.radius,this.radius,0);
this.radius = sprite.getRadius();
imageNum ++;
}else if (imageNum == 11){
sprite = new Sprite(Sprite.MINE3,this.position,new Vector2D(0,0),this.radius,this.radius,0);
this.radius = sprite.getRadius();
imageNum ++;
}else if (imageNum == 12){
sprite = new Sprite(Sprite.MINE2,this.position,new Vector2D(0,0),this.radius,this.radius,0);
this.radius = sprite.getRadius();
imageNum ++;
}else if (imageNum == 13){
sprite = new Sprite(Sprite.MINE1,this.position,new Vector2D(0,0),this.radius,this.radius,0);
this.radius = sprite.getRadius();
imageNum = 1;
}
sprite.draw(g);
}
你可以在新圖像的成功設置後寫一個時間戳,並檢查當前時間戳與最後一個時間戳。如果時間不同,只要做下一次更新即可。 – SomeJavaGuy