Sprite library in a game

This tell us some ! Looking at your for loop you have got 3 for loops stuck together where one is the outer and two are the inner. Which can produce some sluggish results. Also use of ArrayList can bog it down Array could be more effective. I think we still require more context. Could you replicate the problem with a smaller version of your program so we get to properly see ?

Yes I am working on drawing more efficient with the for loops but they arent the cause of the 5 fps. I am trying to make a smaller version now with the problem. Thank you in advance and for your help

You want to avoid creating the ArrayList multiple times. The best way is to create it once and clear it out when reqd like this

ArrayList<Tile> temp = new ArrayList<Tile>();

void drawTiles() {
  for (int y = 0; y < size; y++) {
    temp.clear(); // removes all objects from the list
    for (int x = 0; x < size; x++) {
      int z = (x+2) % 2;
      Tile current = mapGrid[x][y];
      if (z == 1) {
        temp.add(current);
      } else {
        current.drawIfOnScreen();
      }
    }
    for (Tile t : temp) {
      t.drawIfOnScreen();
    }
  }
}

Why do you need to draw the even ‘x’ positions before the odd ones?

3 Likes