1
\$\begingroup\$

I'm trying to optimize my game. I've got object Handler that goes trought all objects and then render and tick them. If I have lot of objects in game game lags or don't start. Could you please help me? public class Handler {

public LinkedList<GameObject> object = new LinkedList<GameObject>();

private GameObject tempObject;

private Camera cam;

public Handler(Camera cam) {
    this.cam = cam;
}

public void tick() {

    for (int i = 0; i < object.size(); i++) {
        tempObject = object.get(i);

        tempObject.tick(object);

    }

}

public void render(Graphics g) {

    for (int i = 0; i < object.size(); i++) {
        tempObject = object.get(i);

        tempObject.render(g);

    }

}
\$\endgroup\$
1
\$\begingroup\$

First tip, don't use a linked list. At least not in this way. Use an ArrayList instead. If you absolutely have to use a linked list use an iterator.

Secondly it's probably a good idea to cull stuff on your screen. That should get you going for a while. Although I am willing to bet there are performance issues elsewhere as well.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.