I am making a space-themed shooter game, and I need to render many "lasers" at the same time. I am using the library Slick2D, a wrapper around lwjgl. Unfortunately, when there are a lot of these "lasers" on the screen at one time, the game drops from its usual 60 FPS to around 30 or even 20.

Things I've noticed:

  • Not calling drawSelf = no lag
  • Not calling .fill = no lag
  • As is = lag as stated in title

public void drawSelf(Graphics g){
    int[] pos = tr.toSlick(blast.getPosition());
    Circle circle = new Circle(pos[0], pos[1], tr.xscale/2);

public int[] toSlick(float x, float y){
    int [] output = new int[2];
    output[0] = (int)(x*xscale+width/2);
    output[1] = (int)(-1*y*yscale+height/2);
    return output;

tr is the coordinate transformer object (I'm using jbox2d physics, but that's not impacting anything), and blast is the "Body".

Can I have some suggestions on making this code faster or am I stuck because of Slick's internals?

  • 1
    \$\begingroup\$ What happens if you remove the .fill() call? \$\endgroup\$ – 200_success Aug 21 '15 at 4:48
  • \$\begingroup\$ @200_success hmm, I have not tried that. I will update my question when I do. \$\endgroup\$ – Blue Aug 21 '15 at 11:09

By looking at documentation, I found another method that is faster at drawing many circles.

I replaced last 2 lines in drawSelf with:


and I got a lot less lag. Turns out it did have to do with internals.


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.