Skip to main content
deleted 10 characters in body; edited title
Source Link
Jamal
  • 34.9k
  • 13
  • 133
  • 237

Slick Lags when drawing Drawing 800+ circles in a space-themed shoorter game

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

Things I've noticed-:

  • notNot calling drawSelf = no lag
  • notNot calling .fill = no lag
  • asAs is = lag as stated in title

Here is the code:

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

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 to makeon making this code faster or am I stuck because of Slick's internals?

Slick Lags when drawing 800+ circles

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 it's usual 60fps 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

Here is the code:

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

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 to make this code faster or am I stuck because of Slick's internals?

Drawing 800+ circles in a space-themed shoorter game

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());
    g.setColor(Color.green);
    Circle circle = new Circle(pos[0], pos[1], tr.xscale/2);
    g.fill(circle);
}

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?

Tweeted twitter.com/#!/StackCodeReview/status/634903452376793088
added more observations
Source Link
Blue
  • 574
  • 2
  • 11

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 it's usual 60fps 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

Here is the code:

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

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 to make this code faster or am I stuck because of Slick's internals?

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 it's usual 60fps to around 30 or even 20.

Here is the code:

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

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 to make this code faster or am I stuck because of Slick's internals?

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 it's usual 60fps 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

Here is the code:

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

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 to make this code faster or am I stuck because of Slick's internals?

edited tags
Link
200_success
  • 144.2k
  • 22
  • 188
  • 473
Source Link
Blue
  • 574
  • 2
  • 11
Loading