So I was wondering how to run through a multi-dimensional array without having to use for loops to test whether or not the objects are intersecting in a rectangle and then render the interesting?
Currently I'm using two for loops to go through it and within the nested loop I have to use the intersecting()
method and since this needs to happen every frame my game is getting low FPS. I assume it's because I have 650x350 entities in my array. I'll show the code below and restate the question. So my official question is how do I test whether or not an entity is intersecting with my rectangle camera so that it doesn't lag the game?
for (int x = 0; x < entities.length; x++) // entities.length is 650
{
for (int y = 0; y < entities[0].length; y++) // entities[0].length is 350
{
if (camera.intersecting(entities[x][y]))
{
entities[x][y].render(g); // X and Y indices are multiplied by 32 to get the position
}
}
}