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.