我试过在java中制作一个只运行一次的循环,
package com.notelek.programs.flat;
import java.awt.event.KeyEvent;
import com.notelek.programs.flat.input.Controller;
public class Game {
public static int time;
public Controller controls;
public Game(){
controls = new Controller();
}
public void tick(Boolean[] key){
time++;
Boolean forward = key[KeyEvent.VK_W];
Boolean back = key[KeyEvent.VK_S];
Boolean left = key[KeyEvent.VK_A];
Boolean right = key[KeyEvent.VK_D];
Boolean turnLeft = key[KeyEvent.VK_LEFT];
Boolean turnRight = key[KeyEvent.VK_RIGHT];
for(Boolean i = true; i == true; i = false){
forward = true;
back = true;
left = true;
right = true;
turnLeft = true;
turnRight = true;
}
controls.tick(forward,back,left,right,turnLeft,turnRight);
}
}
那是我的代码,我需要将向前向后向左向右转左转右变量全部设置为 true,然后快速(在一秒钟内)返回 false 有谁知道这样做的简单方法?