我是一名新手程序员,我正在用Java编写我的第一个游戏,我刚刚实现了一个目标AI,现在每当我运行它时,总是滞后于开始,我想解释为什么请或者某种方法这个更好,谢谢你提前.
代码:(对于最可能造成滞后的因素)
public class Handler {
//Use Linked Lists
private Animator a;
private boolean renderMini;
private int x, y;
public LinkedList<GameObject> object = new LinkedList<GameObject>();
public LinkedList<EntityObject> entity = new LinkedList<EntityObject>();
public LinkedList<Faction> faction = new LinkedList<Faction>();
public Handler(){
a = new Animator();
this.renderMini = false;
}
public void render(Graphics g){
///if(GameMain.numFrames > 5){
if(renderMini){
a.AnimateMini(g, x, y, 32, 32);
}
for(int i = 0; i < entity.size(); i++){
EntityObject tempObject = entity.get(i);
tempObject.render(g);
}
for(int i = 0; i …Run Code Online (Sandbox Code Playgroud)