(事件監聽器在另一個類中)當Game.render = true時,我得到一串不斷流出的子彈,看起來更像激光束,我希望有空隙。我的意思是,我希望子彈能夠像從機關槍發射一樣產生。我知道我應該增加一些時間或某些東西,但我不知道如何去做,以獲得我想要的效果。任何幫助將不勝感激,因爲我一直試圖讓這個工作大約一個小時。我該如何推遲每一顆子彈? (Java -Slick2d - Game)
import java.util.ArrayList;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.SlickException;
public class Bullet {
// ArrayList
@SuppressWarnings("unchecked")
static ArrayList<Bullet> arrL = new ArrayList();
public Bullet(int x , int y) throws SlickException{
}
public static void update(GameContainer gc, int u) throws SlickException{
// when the left mouse button is clicked Game.fire = true, the key listener is in another class
if(Game.fire){
Bullet b = new Bullet(5,5);
arrL.add(b);
reloaded = false;
} if(!reloaded){
}
}
public static void renderBullets(GameContainer gc, Graphics g, int x, int y) {
// draws a new bullet for every 'bullet object' in the ArrayList called arrL
for(Bullet b : arrL){
g.drawRect(x,y,10,10);
x++;
}
}
}
這是應該究竟如何做。 – 2013-04-15 11:13:50
我會把它改成'time + = default_bullet_delay',這樣火焰的速度就是恆定的。 – 2013-09-14 03:45:49