libGDX: Lag when drawing single TextureRegion multiple times

Hello all,
I am building a game where you are basically drawing little dots on the screen with the help of the accelerometer. I am using a single instance of an Actor where I store the coordinates that needs to be drawn inside a List instance then in the draw method I loop through them all and draw the same picture at different coordinates like that:

@Override
public void draw(Batch batch, float parentAlpha) {
for (Custom2dCoordinate coordinate : coordinates) {
batch.draw(
textureRegion,
coordinate.x,
coordinate.y,
getOriginX(),
getOriginY(),
textureRegion.getRegionWidth(),
textureRegion.getRegionHeight(),
getScaleX(), getScaleY(), coordinate.getRotation());

}

}

When a button is pressed 60 new coordinates are added per second. The problem is when I have a really big number of coordinates to draw from the list the game starts to lag. I think the problem might be in drawing the same picture again and again or that I create a new instance of my class Custom2dCoordinate every time I add coordinates to the ArrayList but I don’t know what else to use for the effect that I want. I am looking for suggestions for optimization of the drawing to eliminate the lag. A pool is not an option because I am not removing objects. Any help and suggestions would be appreciated.

Render new sprites into an FBO, render the FBO to screen.

This way you only render the number of sprites that were added in that very frame.

He is using LibGDX, this is probably a bit overkill.

If you are adding a new texture to the list every iteration of the game loop then it only takes about 40 seconds to fill that list to 25,000 objects that it has to update and draw.

I suggest to cut down is to remove overlapping objects, there is no point in drawing an object when there is another object on top of it hiding it.

How big is this picture? As 25,000 objects being drawn at once is actually enough to lag a PC never mind a phone, depending of course but generally 25,000 objects all doing something and been drawn will generate some lag.

It is actually really easy to do beacuse you have the classes to do it.


Thanks for your answers. I’ll try both of your suggestions. The picture that I am using is 32 x 32 and has 15% transperancy so it is important to draw it every time to achieve the desired effect.