现在,我知道有人问过这个问题,但我需要知道如何在 html 或任何东西上执行此操作。这是我的代码,不包括所有其他 java 文件。
package rtype;
import java.awt.Image;
import java.awt.event.KeyEvent;
import java.util.ArrayList;
import javax.swing.ImageIcon;
public class aa {
private int xd;
private int yd;
private int dx;
private int dy;
private int x;
private int y;
private Image image;
private ArrayList missiles;
private final int CRAFT_SIZE = 70;
public aa() {
ImageIcon ii = new ImageIcon(this.getClass().getResource("/aa.png"));
image = ii.getImage();
missiles = new ArrayList();
x = 10;
y = 10;
xd = -14;
yd = 140;
}
public void move() {
if(y >=xd)
y += dx;
else if(y < xd)
y += 1;
if(y <=yd)
y += dy;
else if(y > yd)
y += -1;
}
public int getX() {
return x;
}
public int getY() {
return y;
}
public Image getImage() {
return image;
}
public ArrayList getMissiles() {
return missiles;
}
public void keyPressed(KeyEvent e) {
int key = e.getKeyCode();
if (key == KeyEvent.VK_SPACE) {
fire();
}
if (key == KeyEvent.VK_UP) {
dy = -1;
}
if (key == KeyEvent.VK_DOWN) {
dy = 1;
}
if (key == KeyEvent.VK_RIGHT) {
yd++;
}
if (key == KeyEvent.VK_LEFT) {
yd--;
}
if (key == KeyEvent.VK_W) {
xd++;
}
if (key == KeyEvent.VK_S) {
xd--;
}
}
public void fire() {
try{
missiles.add(new Missle(x + CRAFT_SIZE, y + CRAFT_SIZE));
}catch(Exception e){}
}
public void keyReleased(KeyEvent e) {
int key = e.getKeyCode();
if (key == KeyEvent.VK_UP) {
dy = 0;
}
if (key == KeyEvent.VK_DOWN) {
dy = 0;
}
}
}
因此,在 fire() 方法中,我想让它在两次拍摄之间延迟。如何?
对不起,如果这是 n00bish